Java Map MCQs with answers Page - 4

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 of the following is not a valid Map implementation?

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

A

Admin • 831.35K Points
Coach

Q. What is returned by `containsValue()` method?

  • (A) True if value exists
  • (B) Value
  • (C) Key
  • (D) Set of values

A

Admin • 831.35K Points
Coach

Q. Which class is ideal for caching recently used items in insertion order?

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

A

Admin • 831.35K Points
Coach

Q. Which Map implementation is sorted and synchronized?

  • (A) TreeMap
  • (B) ConcurrentHashMap
  • (C) Collections.synchronizedMap(new TreeMap<>())
  • (D) LinkedHashMap

A

Admin • 831.35K Points
Coach

Q. What happens when you add a duplicate key to a HashMap?

  • (A) It throws an exception
  • (B) It adds a duplicate entry
  • (C) It updates the existing value
  • (D) It ignores the new entry

A

Admin • 831.35K Points
Coach

Q. Which method is used to iterate over entries in a Map using streams?

  • (A) map()
  • (B) stream()
  • (C) entrySet().stream()
  • (D) keySet().forEach()

A

Admin • 831.35K Points
Coach

Q. Which of these is used to check the presence of a specific mapping?

  • (A) containsEntry()
  • (B) entryExists()
  • (C) containsKey() and containsValue()
  • (D) mapContains()

A

Admin • 831.35K Points
Coach

Q. What will `Map.of()` throw if duplicate keys are provided?

  • (A) DuplicateKeyException
  • (B) IllegalArgumentException
  • (C) RuntimeException
  • (D) No exception

A

Admin • 831.35K Points
Coach

Q. Which Java version introduced `Map.of()` and `Map.ofEntries()` methods?

  • (A) Java 7
  • (B) Java 8
  • (C) Java 9
  • (D) Java 10

A

Admin • 831.35K Points
Coach

Q. Which of the following is a limitation of HashMap?

  • (A) It does not allow duplicate keys
  • (B) It allows only integers
  • (C) It does not maintain any order
  • (D) It is synchronized by default
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