Java Map MCQs with answers Page - 8

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 • 831.35K Points
Coach

Q. Which Map implementation uses hash table and linked list to maintain order?

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

A

Admin • 831.35K Points
Coach

Q. What is returned by the `size()` method of a Map?

  • (A) Number of keys
  • (B) Number of values
  • (C) Number of key-value mappings
  • (D) Map capacity

A

Admin • 831.35K Points
Coach

Q. Which of these maps throws a `NullPointerException` when `null` is used as a key?

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

A

Admin • 831.35K Points
Coach

Q. Which method in the Map interface is used to copy all mappings from one map to another?

  • (A) copy()
  • (B) clone()
  • (C) putAll()
  • (D) mergeAll()

A

Admin • 831.35K Points
Coach

Q. Which of the following is true about `Collections.unmodifiableMap(map)`?

  • (A) It creates a mutable map
  • (B) It creates a copy of the map
  • (C) It creates a read-only view of the map
  • (D) It removes all elements

A

Admin • 831.35K Points
Coach

Q. Which type of Map allows duplicate values but unique keys?

  • (A) All Maps
  • (B) Only TreeMap
  • (C) Only HashMap
  • (D) None

A

Admin • 831.35K Points
Coach

Q. What does `entrySet().iterator()` return?

  • (A) Iterator over keys
  • (B) Iterator over values
  • (C) Iterator over Map.Entry objects
  • (D) Iterator over index

A

Admin • 831.35K Points
Coach

Q. What will happen if you try to modify a map created with `Map.of()`?

  • (A) Modifications are allowed
  • (B) It throws `UnsupportedOperationException`
  • (C) It silently ignores changes
  • (D) It updates only values

A

Admin • 831.35K Points
Coach

Q. Which method is used to get a value or compute and store if absent?

  • (A) get()
  • (B) computeIfAbsent()
  • (C) getOrPut()
  • (D) putIfMissing()
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