Java · Question 25 · Medium

Which Java collection class does NOT allow duplicate elements and keeps elements in the order they were inserted?

  1. LinkedHashSet
  2. HashSet
  3. TreeSet
  4. ArrayList
Answer and explanation

Answer: A. LinkedHashSet

Explanation: LinkedHashSet is a Set, so it rejects duplicates, and its internal linked list keeps insertion order. HashSet has no order guarantee, TreeSet keeps sorted order, and ArrayList allows duplicates.

Previous: What will be the output of the following Java program? · Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge