LinkedHashSet Class In Java

Now come to second Implementation class of set interface is LinkedHashSet. It's very similar to HashSet class. LinkedHashSet class maintain insertion order.

We can say that LinkedHashSet Class is an orderable version of HashSet Class. LinkedHashSet manages doubly-linked list for all elements. 
As per list interface property, LinkedHashSet maintains insertion order.

When we iterating a HashSet the order is random, while a LinkedHashSet iterate elements in the order in which they were inserted.

 

Syntax:

LinkedHashSet<String> lhs = new LinkedHashSet<String>();

Related Articles

post a comment