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>
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
ConstructorsConstructorDescriptionConstructs a new empty instance ofLinkedHashSet.LinkedHashSet(int capacity) Constructs a new instance ofLinkedHashSetwith the specified capacity.LinkedHashSet(int capacity, float loadFactor) Constructs a new instance ofLinkedHashSetwith the specified capacity and load factor.LinkedHashSet(Collection<? extends E> collection) Constructs a new instance ofLinkedHashSetcontaining the unique elements in the specified collection. -
Method Summary
Methods inherited from class HashSet
add, clear, contains, isEmpty, iterator, remove, sizeModifier and TypeMethodDescriptionbooleanAdds the specified object to thisHashSetif not already present.voidclear()Removes all elements from thisHashSet, leaving it empty.booleanSearches thisHashSetfor the specified object.booleanisEmpty()Returns true if thisHashSethas no elements, false otherwise.iterator()Returns an Iterator on the elements of thisHashSet.booleanRemoves the specified object from thisHashSet.intsize()Returns the number of elements in thisHashSet.Methods inherited from class AbstractSet
equals, hashCode, removeAllModifier and TypeMethodDescriptionbooleanCompares the specified object to this Set and returns true if they are equal.inthashCode()Returns the hash code for this set.booleanremoveAll(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, toStringModifier and TypeMethodDescriptionbooleanaddAll(Collection<? extends E> collection) Attempts to add all of the objects contained incollectionto the contents of thisCollection(optional).booleancontainsAll(Collection<?> collection) Tests whether thisCollectioncontains all objects contained in the specifiedCollection.booleanretainAll(Collection<?> collection) Removes all objects from thisCollectionthat are not also found in theCollectionpassed (optional).Object[]toArray()Returns a new array containing all elements contained in thisArrayList.<T> T[]toArray(T[] contents) Returns an array containing all elements contained in thisArrayList.toString()Returns the string representation of thisCollection.Methods inherited from class Object
clone, getClass, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()final ClassgetClass()Returns the runtime class of an object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(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 voidwait(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, toArrayModifier and TypeMethodDescriptionbooleanaddAll(Collection<? extends E> collection) Adds the objects in the specified collection which do not exist yet in this set.booleancontainsAll(Collection<?> collection) Searches this set for all objects in the specified collection.booleanretainAll(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 ofLinkedHashSet. -
LinkedHashSet
public LinkedHashSet(int capacity) Constructs a new instance ofLinkedHashSetwith the specified capacity.- Parameters:
capacity- the initial capacity of thisLinkedHashSet.
-
LinkedHashSet
public LinkedHashSet(int capacity, float loadFactor) Constructs a new instance ofLinkedHashSetwith the specified capacity and load factor.- Parameters:
capacity- the initial capacity.loadFactor- the initial load factor.
-
LinkedHashSet
Constructs a new instance ofLinkedHashSetcontaining the unique elements in the specified collection.- Parameters:
collection- the collection of elements to add.
-