LinkedHashSet:

  • It is the child interface of HashSet.
  • It was introduced as 1.4 version.
  • Here the underlying data structure is HashTable+LinkedList, which is known as hybrid data structure.
  • Insertion order is preserved.
  • LinkedHashSet is the best choice to develop cache based application where duplicates are not allowed and insertion order must be preserved.

Let's see a simple demo program on LinkedHashSet.

LinkedHashSetDemo.java:

   import java.util.*;
   class LinkedHashSetDemo
      {
         public static void main(String[] args)
               {
                  LinkedHashSet l = new LinkedHashSet();
                  l.add("Gourav");
                  l.add("Abhisek");
                  l.add("Lagnika");
                  l.add("Priti");
                  l.add("Suman");
                  l.add("Sonali");
                  l.add(null);
                  l.add(25);
                  System.out.println(l.add("Gourav"));
                  System.out.println(l);
               }
      }

Output

false
[Gourav, Abhisek, Lagnika, Priti, Suman, Sonali, null, 25]

 

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment