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

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements