# Class LinkedHashSet<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.HashSet<E>
java.util.LinkedHashSet<E>

All Implemented Interfaces:
  `Iterable<E>, Collection<E>, Set<E>`

public class LinkedHashSet<E> extends HashSet<E> implements Set<E>
LinkedHashSet is a variant of HashSet. Its entries are kept in a doubly-linked list. The iteration order is the order in which entries were inserted.

Null elements are allowed, and all the optional Set operations are supported.

Like HashSet, LinkedHashSet is not thread safe, so access by multiple threads must be synchronized by an external mechanism such as `Collections.synchronizedSet(Set)`.

Since:
  1.4

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LinkedHashSet()`
  Constructs a new empty instance of `LinkedHashSet`.
  `LinkedHashSet(int capacity)`
  Constructs a new instance of `LinkedHashSet` with the specified capacity.
  `LinkedHashSet(int capacity, float loadFactor)`
  Constructs a new instance of `LinkedHashSet` with the specified capacity and load factor.
  `LinkedHashSet(Collection<? extends E> collection)`
  Constructs a new instance of `LinkedHashSet` containing the unique elements in the specified collection.

- ## Method Summary

  ### Methods inherited from class HashSet

  `add, clear, contains, isEmpty, iterator, remove, size`
  Modifier and Type
  Method
  Description
  `boolean`
  `add(E object)`
  Adds the specified object to this `HashSet` if not already present.
  `void`
  `clear()`
  Removes all elements from this `HashSet`, leaving it empty.
  `boolean`
  `contains(Object object)`
  Searches this `HashSet` for the specified object.
  `boolean`
  `isEmpty()`
  Returns true if this `HashSet` has no elements, false otherwise.
  `Iterator<E>`
  `iterator()`
  Returns an Iterator on the elements of this `HashSet`.
  `boolean`
  `remove(Object object)`
  Removes the specified object from this `HashSet`.
  `int`
  `size()`
  Returns the number of elements in this `HashSet`.

  ### Methods inherited from class AbstractSet

  `equals, hashCode, removeAll`
  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object object)`
  Compares the specified object to this Set and returns true if they are equal.
  `int`
  `hashCode()`
  Returns the hash code for this set.
  `boolean`
  `removeAll(Collection<?> collection)`
  Removes all occurrences in this collection which are contained in the specified collection.

  ### Methods inherited from class AbstractCollection

  `addAll, containsAll, retainAll, toArray, toArray, toString`
  Modifier and Type
  Method
  Description
  `boolean`
  `addAll(Collection<? extends E> collection)`
  Attempts to add all of the objects contained in `collection` to the contents of this `Collection` (optional).
  `boolean`
  `containsAll(Collection<?> collection)`
  Tests whether this `Collection` contains all objects contained in the specified `Collection`.
  `boolean`
  `retainAll(Collection<?> collection)`
  Removes all objects from this `Collection` that are not also found in the `Collection` passed (optional).
  `Object[]`
  `toArray()`
  Returns a new array containing all elements contained in this `ArrayList`.
  `<T> T[]`
  `toArray(T[] contents)`
  Returns an array containing all elements contained in this `ArrayList`.
  `String`
  `toString()`
  Returns the string representation of this `Collection`.

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

  ### Methods inherited from interface Set

  `addAll, containsAll, retainAll, toArray, toArray`
  Modifier and Type
  Method
  Description
  `boolean`
  `addAll(Collection<? extends E> collection)`
  Adds the objects in the specified collection which do not exist yet in this set.
  `boolean`
  `containsAll(Collection<?> collection)`
  Searches this set for all objects in the specified collection.
  `boolean`
  `retainAll(Collection<?> collection)`
  Removes all objects from this set that are not contained in the specified collection.
  `Object[]`
  `toArray()`
  Returns an array containing all elements contained in this set.
  `<T> T[]`
  `toArray(T[] array)`
  Returns an array containing all elements contained in this set.

- ## Constructor Details

  - ### LinkedHashSet

    public LinkedHashSet()
    Constructs a new empty instance of `LinkedHashSet`.

  - ### LinkedHashSet

    public LinkedHashSet(int capacity)
    Constructs a new instance of `LinkedHashSet` with the specified capacity.
    Parameters:
      `capacity` - the initial capacity of this `LinkedHashSet`.

  - ### LinkedHashSet

    public LinkedHashSet(int capacity, float loadFactor)
    Constructs a new instance of `LinkedHashSet` with the specified capacity and load factor.
    Parameters:
      `capacity` - the initial capacity.
      `loadFactor` - the initial load factor.

  - ### LinkedHashSet

    public LinkedHashSet(Collection<? extends E> collection)
    Constructs a new instance of `LinkedHashSet` containing the unique elements in the specified collection.
    Parameters:
      `collection` - the collection of elements to add.