LearnFrenzy
Sign in Take a free test

HashMap and TreeMap · HashMap and TreeMap MCQ · Question 14

Grouping with computeIfAbsent Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 14 Back to Exercise

What does groups.computeIfAbsent(k, x -> new ArrayList<>()).add(v) do?

  • A Replaces the list each time
  • B Creates a list the first time k is seen and adds v to the list for k Correct
  • C Throws if k exists
  • D Adds k to every list
Correct Answer: Option B

computeIfAbsent returns the existing or newly created value.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links