linkedhashset

Learn LinkedHashSet Class in Java with Programming Example

linkedhashsetIn this chapter you will learn:

  1. What is LinkedHashSet Class in Java
  2. Declaration and Methods of LinkedHashSet Class
  3. Programming Example
 What is LinkedHashSet Class in Java?

LinkedHashSet is an implementation of HashSet in a linked list with predictable iteration order. It is different from HashSet as it maintains doubly linked list through its all entries. Linked list maintain the insertion order so the items are stored in Linked Hash Table as the order they inserted. It inherits all the methods of set operation and allow null element entry.

Constructors

ConstructorsDescriptions
LinkedHashSet()Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).
LinkedHashSet(Collection<?
extends E> c)
Constructs a new linked hash set with the same elements as the specified collection.
LinkedHashSet(int initialCapacity)Constructs a new, empty linked hash set with the specified initial capacity and the default load factor (0.75).
LinkedHashSet(int initialCapacity,
float loadFactor)
Constructs a new, empty linked hash set with the specified initial capacity and load factor.

Methods Inherited From Class

ClassMethods
java.util.HashSetadd(), clear(), clone(), contains(), isEmpty(), iterator(), remove(), size()
java.util.AbstractSetequals(), hashCode(), removeAll()
java.util.AbstractCollectionaddAll(), containsAll(), retainAll(), toArray(), toArray(), toString()
java.lang.Objectfinalize(), getClass(), notify(), notifyAll(), wait(), wait(), wait()
java.util.Setadd(), addAll(), clear(), contains(), containsAll(), equals(), hashCode(), isEmpty(), iterator(), remove(), removeAll(), retainAll(), size(), toArray(), toArray()

Declaration:

Programming Example

Output

D:\JavaProgram>javac LinkedHashSet_Example.java
D:\JavaProgram>java LinkedHashSet_ExampleC# Java SQL PHP HTML
Item Removed : true
[C#, Java, PHP, HTML]
_

Summary

In this chapter you learned LinkedHashSet class in java with programming example. In the next chapter you will learn TreeSet Class in Java.



Leave a Reply

Your email address will not be published. Required fields are marked *