Java Map MCQs with answers Page - 7

You will find multiple-choice questions (MCQs) related to #Java Map here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 833.24K Points
Coach

Q. Which method returns a shallow copy of a Map?

  • (A) clone()
  • (B) copy()
  • (C) duplicate()
  • (D) replicate()

A

Admin • 833.24K Points
Coach

Q. What happens if you pass a null key to `TreeMap`?

  • (A) It stores the key
  • (B) It throws NullPointerException
  • (C) It replaces previous null key
  • (D) It is ignored

A

Admin • 833.24K Points
Coach

Q. What is returned by `computeIfPresent()` in Map?

  • (A) New value if computation succeeds
  • (B) Key
  • (C) Old value
  • (D) Nothing

A

Admin • 833.24K Points
Coach

Q. What will `map.getOrDefault(“key”, “default”)` return if key is not found?

  • (A) Exception
  • (B) null
  • (C) “default”
  • (D) 0

A

Admin • 833.24K Points
Coach

Q. Which is the default load factor of HashMap?

  • (A) 0.5
  • (B) 0.65
  • (C) 0.75
  • (D) 1.0

A

Admin • 833.24K Points
Coach

Q. Which Map implementation is sorted and allows null values but not null keys?

  • (A) HashMap
  • (B) TreeMap
  • (C) LinkedHashMap
  • (D) EnumMap

A

Admin • 833.24K Points
Coach

Q. Which of the following guarantees thread-safety?

  • (A) HashMap
  • (B) TreeMap
  • (C) ConcurrentHashMap
  • (D) LinkedHashMap

A

Admin • 833.24K Points
Coach

Q. Which of the following operations is NOT supported by `Map.of()`?

  • (A) Iteration
  • (B) Reading values
  • (C) Adding new entries
  • (D) Accessing keys

A

Admin • 833.24K Points
Coach

Q. Which Map is ideal for maintaining access order?

  • (A) TreeMap
  • (B) LinkedHashMap with accessOrder=true
  • (C) HashMap
  • (D) EnumMap

A

Admin • 833.24K Points
Coach

Q. Which method in the Map interface is used to remove a mapping only if the key is mapped to a specific value?

  • (A) remove()
  • (B) removeIfMatch()
  • (C) conditionalRemove()
  • (D) remove(key, value)
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More