Monday 28 May 2018

Difference between Set and List




List
Set
Insertion Order
List maintains insertion order in which element are added.
Most of the Set implementation does not maintains an insertion order.
For ex:HashSet.
LinkedHashSet does maintain insertion order.
TreeSet are sorted by natural order.
Duplicate
Allows to store duplicate elements in java.
Does not allow duplicate elements.
Null Keys
Allow to store any number of null values.
Most of the Set implementation only allow one null values.

Tree Set does not allow any null value.
Implementing Classes
ArrayList,Linkedlist,Vector etc.
HashSet,LinkedHashSet,TreeSet etc.
Structure
List are resizable array.
Set uses map for their internal implementation.
Index based
List are index based structure. Hence element can be retrieved based on index.
Set is not index based collection.


Enjoy Reading.


No comments:

Post a Comment