Java Set MCQs with answers Page - 8

You will find multiple-choice questions (MCQs) related to #Java Set 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 • 828.43K Points
Coach

Q. What does the `descendingSet()` method of NavigableSet return?

  • (A) A random subset
  • (B) A reversed view of the Set
  • (C) Only null elements
  • (D) A copy of the Set

A

Admin • 828.43K Points
Coach

Q. Can EnumSet be empty?

  • (A) No
  • (B) Yes, using EnumSet.noneOf()
  • (C) Yes, using EnumSet.clear()
  • (D) Only if using TreeMap

A

Admin • 828.43K Points
Coach

Q. Which implementation allows predictable iteration order in Set?

  • (A) HashSet
  • (B) LinkedHashSet
  • (C) TreeSet
  • (D) EnumSet

A

Admin • 828.43K Points
Coach

Q. Which of these Set classes can be used with null values?

  • (A) HashSet
  • (B) TreeSet
  • (C) EnumSet
  • (D) ConcurrentSkipListSet

A

Admin • 828.43K Points
Coach

Q. Which operation on TreeSet returns the greatest element less than the given element?

  • (A) higher()
  • (B) ceiling()
  • (C) floor()
  • (D) lower()

A

Admin • 828.43K Points
Coach

Q. Which of these is TRUE for HashSet?

  • (A) It is thread-safe
  • (B) It preserves insertion order
  • (C) It allows multiple null values
  • (D) It allows constant-time operations

A

Admin • 828.43K Points
Coach

Q. Which Set implementation is ideal when concurrency is required and order matters?

  • (A) HashSet
  • (B) ConcurrentSkipListSet
  • (C) TreeSet
  • (D) LinkedHashSet

A

Admin • 828.43K Points
Coach

Q. What is the result of calling clear() on a Set?

  • (A) Removes last element
  • (B) Removes only null elements
  • (C) Removes all elements
  • (D) Throws exception

A

Admin • 828.43K Points
Coach

Q. Which of these is best suited for creating a range of enum values in a Set?

  • (A) EnumSet.range()
  • (B) TreeSet.range()
  • (C) HashSet.subSet()
  • (D) Set.rangeOf()

A

Admin • 828.43K Points
Coach

Q. Which method in NavigableSet returns the least element greater than the given element?

  • (A) lower()
  • (B) higher()
  • (C) floor()
  • (D) ceiling()
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