Java LinkedHashMap Tutorial with Example program



Class LinkedHashMap


Type Parameters:
    K - the type of keys maintained by this map
    V - the type of mapped values

All Implemented Interfaces:

    Serializable, Cloneable, Map

public class LinkedHashMap
extends HashMap
implements Map
{
//

}


Since:
    1.4
   
See Also:
    Object.hashCode(), Collection, Map, HashMap, TreeMap, Hashtable, Serialized Form

Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry


Constructors summary

LinkedHashMap()
    Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).
   
LinkedHashMap(int initialCapacity)
    Constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75).
   
LinkedHashMap(int initialCapacity, float loadFactor)
    Constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor.
   
LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
    Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.
   
LinkedHashMap(Map m)
    Constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.


Methods
summary

void clear()
    Removes all of the mappings from this map.
   
boolean containsValue(Object value)
    Returns true if this map maps one or more keys to the specified value.
   
V get(Object key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
   
protected boolean removeEldestEntry(Map.Entry eldest)
    Returns true if this map should remove its eldest entry.

Methods inherited from class java.util.HashMap


public boolean containsKey(Object key)
    Returns true if this map contains a mapping for the specified key.

public Set> entrySet()
    Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
 
public boolean isEmpty()
    Returns true if this map contains no key-value mappings.

public Set keySet()
    Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

public V put(K key,V value)
    Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.  
  
public void putAll(Map m)
    Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
  
public V remove(Object key)
    Removes the mapping for the specified key from this map if present.  
  
public int size()
    Returns the number of key-value mappings in this map.
   
public Collection values()
    Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait,clone,equals, hashCode, toString



Related Post

Comments


©candidjava.com