Java Set MCQs with answers Page - 6

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

Q. Can HashSet contain different types of objects?

  • (A) Yes, if not using generics
  • (B) No, only homogeneous types
  • (C) Yes, only null values
  • (D) Yes, but only if extending the same parent

A

Admin • 833K Points
Coach

Q. What does Set's `equals()` method check?

  • (A) Whether order and values match
  • (B) Only if objects are same
  • (C) Whether both Sets contain the same elements
  • (D) Whether Sets have same memory reference

A

Admin • 833K Points
Coach

Q. What will be the result of: new HashSet<>(Arrays.asList(1,2,2,3))?

  • (A) [1,2,2,3]
  • (B) [1,2,3]
  • (C) [1,2,2]
  • (D) Error

A

Admin • 833K Points
Coach

Q. What is returned by Set's `add()` method when element already exists?

  • (A) true
  • (B) false
  • (C) null
  • (D) exception

A

Admin • 833K Points
Coach

Q. Which class is most efficient for representing a set of enum constants?

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

A

Admin • 833K Points
Coach

Q. Which operation is NOT supported by Set?

  • (A) Add element
  • (B) Remove element
  • (C) Get element by index
  • (D) Check for presence of element

A

Admin • 833K Points
Coach

Q. Which of the following Set implementations is thread-safe?

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

A

Admin • 833K Points
Coach

Q. Which Java version introduced NavigableSet?

  • (A) Java 5
  • (B) Java 6
  • (C) Java 7
  • (D) Java 8

A

Admin • 833K Points
Coach

Q. Which of the following methods belong to the NavigableSet interface?

  • (A) ceiling(), floor(), higher(), lower()
  • (B) insert(), update(), delete()
  • (C) append(), prepend()
  • (D) sort(), shuffle()

A

Admin • 833K Points
Coach

Q. Which of the following Set implementations is not ordered and not sorted?

  • (A) HashSet
  • (B) TreeSet
  • (C) LinkedHashSet
  • (D) EnumSet
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