Java LinkedHashSet Tutorial with Example program



Class LinkedHashSet



Type Parameters:
    E - the type of elements maintained by this set
    
All Implemented Interfaces:
    Serializable, Cloneable, Iterable, Collection, Set

public class LinkedHashSet
extends HashSet
implements Set, Cloneable, Serializable
{
//
}


Since:
    1.4
    
See Also:
    Object.hashCode(), Collection, Set, HashSet, TreeSet, Hashtable, Serialized Form
    
Constructors summary
LinkedHashSet()
    Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).
    
LinkedHashSet(Collection 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.
    
Method summary
    
Methods inherited from class java.util.HashSet
public boolean add(E e)
    Adds the specified element to this set if it is not already present. More formally, adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false.
    
public void clear()
    Removes all of the elements from this set. The set will be empty after this call returns.

public boolean contains(Object o)
    Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).

public boolean isEmpty()
    Returns true if this set contains no elements.    
    
public Iterator iterator()
    Returns an iterator over the elements in this set. The elements are returned in no particular order.
    
public boolean remove(Object o)
    Removes the specified element from this set if it is present. More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this set contains such an element. Returns true if this set contained the element (or equivalently, if this set changed as a result of the call). (This set will not contain the element once the call returns.)
    
public int size()
    Returns the number of elements in this set (its cardinality).
    
public boolean removeAll(Collection c)
    Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.
    
public boolean addAll(Collection c)
    Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
    This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.
    Note that this implementation will throw an UnsupportedOperationException unless add is overridden (assuming the specified collection is non-empty).

public boolean containsAll(Collection c)
    Returns true if this collection contains all of the elements in the specified collection.
    This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true is returned, otherwise false.

public boolean retainAll(Collection c)
    Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
    This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.
    Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.
    
public Object[] toArray()
    Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
    The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.
    This method acts as bridge between array-based and collection-based APIs.    
    
public T[] toArray(T[] a)
    Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.
    
public void clear()
    Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.    
    
    
Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait,equals,hashcode,toString
    
    
    




Related Post

Comments


©candidjava.com