#1. Difference Between List And Set In Java

A Collection in Java is an Object that represents a group of Objects and the Collection Framework consists of multiple classes and interfaces which can be used for various data manipulation operations.

List and Set both are Interfaces in Java and extend the most basic interface Collection interface. We will learn the basic differences between both.

  1. List stores the element in the order it is inserted whereas Set does not. However, an implemented class of Set named LinkedHashSet stores elements in the insertion order.
  2. Since List is an ordered collection we can use the index to access any element directly which is not possible in Set.
  3. The List can contain duplicate elements but the Set can not.
  4. We can have multiple NULL elements in a List but the Set can have only one NULL element.
  5. The important implemented classes of List are ArrayList, LinkedList and Vector. LinkedHashSet, TreeSet and HashSet are important implemented classes of the Set interface.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *