Java Map MCQs with answers Page - 6

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 of the following methods is used to access all key-value mappings?

  • (A) entries()
  • (B) getAll()
  • (C) entrySet()
  • (D) mapAll()

A

Admin • 833.24K Points
Coach

Q. Which Map allows only keys from a specific enum type?

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

A

Admin • 833.24K Points
Coach

Q. Which of the following is a true statement about HashMap?

  • (A) It preserves key order
  • (B) It allows duplicate keys
  • (C) It is thread-safe
  • (D) It allows one null key

A

Admin • 833.24K Points
Coach

Q. Which of the following is false for TreeMap?

  • (A) It maintains ascending order
  • (B) It allows null keys
  • (C) It implements SortedMap
  • (D) It is not synchronized

A

Admin • 833.24K Points
Coach

Q. Which method is used to apply a function to all entries in a Map?

  • (A) forEach()
  • (B) map()
  • (C) applyAll()
  • (D) loop()

A

Admin • 833.24K Points
Coach

Q. Which exception is thrown if null key is inserted in Hashtable?

  • (A) IllegalArgumentException
  • (B) NullPointerException
  • (C) UnsupportedOperationException
  • (D) IllegalStateException

A

Admin • 833.24K Points
Coach

Q. Which Map should be used when high concurrency is needed?

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

A

Admin • 833.24K Points
Coach

Q. Which is true about Map.of() method?

  • (A) Allows null keys
  • (B) Allows duplicate keys
  • (C) Immutable
  • (D) Thread-unsafe

A

Admin • 833.24K Points
Coach

Q. Which of these Map implementations is ordered and thread-safe?

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

A

Admin • 833.24K Points
Coach

Q. What does `Map.Entry` represent in Java?

  • (A) Only keys in a Map
  • (B) Only values in a Map
  • (C) A key-value pair in a Map
  • (D) An index in a Map
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