Linkedhashset

LinkedHashSet

  •  LinkedHashSet is a sub class of HashSet.
  •  It is implemented based on hybrid data structure, HashTable & LinkedList.
  •  It preserve insertion order
  • Duplicate object are not allowed, null insertion is allowed.
LinkedHashSet Example

public class Linkedhashset
{

   public static void main(String[] args)
	{
		
	
	 LinkedHashSet h1=new LinkedHashSet<>();
    
	h1.add("milan");
	h1.add("vivek");
	h1.add("abhi");
	h1.add("bl");

        System.out.println("size of linked hashset "+h1.size());
	      
	for(Object o1:h1)
	{
		System.out.println(o1);
	}

   }
}

output:

size of linked hashset 4
milan
vivek
abhi
bl

Leave a Reply