LinkedHashSet in Java

LinkedHashSet is maintains the insertion(insert the elements) order in Linked List.Elements get Sorted in the sequence order.

 

We can delete the elements by using remove() method in LinkedHashSet.It is similar to the HashSet and Tree Set but the difference is HashSet doesn’t maintain any order and TreeSet sort the elements in ascending order.

import java.util.*;

class Linkhashset

{

    public static void main(String args[])

    {

     LinkedHashSet al = new  LinkedHashSet();

     al.add("rekha");

     al.add("setia");

     al.add("rahul");

     al.add("deven");

     al.add("seon");

     al.add("siman");

     System.out.println(al); //print all the elements

     al.remove("siman"); //remove an element(siman) from the set

     System.out.println(al); //retrieving elements after removing

    }

}

Output....

LinkedHashSet in Java