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.
- 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.
- Since List is an ordered collection we can use the index to access any element directly which is not possible in Set.
- The List can contain duplicate elements but the Set can not.
- We can have multiple NULL elements in a List but the Set can have only one NULL element.
- 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.