Difference between List and Set in Java?

List is an ordered sequence of elements whereas Set is a distinct list of elements which is unordered.

Point of Distinction List Set
Positional Access Yes No
Duplicates Yes

No. If you try yo insert the duplicate element in Set it would replace the existing value.

Order Ordered. Insertion order is maintained. Depends upon implementation. LInkedHashSet maintains the elements in insertion order.
Null Value Any number of null values One null value in its collection.
Method inside Interface New methods are defined inside List interface. No new methods are defined inside Set interface.
Forward or Backward insertion Both direction using Listiterator. Forward direction with the help of iterator.
Use To store non-unique ordered elements in as per insertion order. To store unique non-ordered elements.
Implementation ArrayList, LinkedList etc. HashSet LinkedHashSet, TreeSet etc.
Legacy Class Vector None

Comments