Java Map MCQs with answers Page - 2

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 method checks whether a Map contains a specific key?

  • (A) hasKey()
  • (B) containsKey()
  • (C) keyExists()
  • (D) findKey()

A

Admin • 831.35K Points
Coach

Q. Which Map implementation allows one null key and multiple null values?

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

A

Admin • 831.35K Points
Coach

Q. What does `entrySet()` return in a Map?

  • (A) List of keys
  • (B) List of values
  • (C) Set of key-value pairs
  • (D) List of keys and values separately

A

Admin • 831.35K Points
Coach

Q. Which class is used to make a Map thread-safe without using Hashtable?

  • (A) Collections.synchronizedMap()
  • (B) ThreadSafeMap
  • (C) ConcurrentMap
  • (D) ConcurrentHashMap

A

Admin • 831.35K Points
Coach

Q. Which Map implementation is best for high-concurrency environments?

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

A

Admin • 831.35K Points
Coach

Q. What is the return type of `putIfAbsent()` in ConcurrentHashMap?

  • (A) boolean
  • (B) void
  • (C) int
  • (D) V

A

Admin • 831.35K Points
Coach

Q. Which Map is sorted by its keys?

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

A

Admin • 831.35K Points
Coach

Q. Which Map implementation does NOT allow null keys or values?

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

A

Admin • 831.35K Points
Coach

Q. Which interface defines `getOrDefault()` method in Java 8?

  • (A) Collection
  • (B) List
  • (C) Map
  • (D) Set

A

Admin • 831.35K Points
Coach

Q. Which method can replace an existing value in a Map only if it is currently mapped to a given value?

  • (A) putIfPresent()
  • (B) replace()
  • (C) override()
  • (D) update()
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