Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

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]

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext