LinkedHashSet in Java


Prev Tutorial Next Tutorial

LinkedHashSet in Java

LinkedHashSet is Implementer class of Set Interface, Which supports hashing mechanism to store the value that means all the elements are stored in the same order as inserted (In unsorted format).

LinkedHashSet

Points to Remember

  • LinkedHashSet does not allow duplicate elements.
  • LinkedHashSet allows to store heterogeneous elements
  • LinkedHashSet is not Synchronized.
  • For retrieving elements from LinkedHashSet you can use foreach loop and iterator interface.
  • LinkedHashSet allows null values.

Example of LinkedHashSet

import java.util.*;

class LHashDemo
{
public static void main(String args[])
	{
	LinkedHashSet<String> lhs=new LinkedHashSet<String>();
	lhs.add("Java");
	lhs.add("C-lang");
	lhs.add("C++");
	lhs.add("Java");
   System.out.println(lhs);
   Iterator i=lhs.iterator();
   System.out.println("Forward Direction");

	while(l.hasNext())
	{
	System.out.println(i.next());
	}
	}
}

Output

Java
C-lang
C++

Prev Tutorial Next Tutorial



Download Projects

Advertisements

FREE Online Google Play APK Downloader

Buy APP Installs, Buy 100% Genuine Installs