LinkedHashSet in Java

Advertisements

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 Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements