public class

LinkedHashMap

extends AbstractMap<K, V>
implements Serializable Map<K, V>
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ com.sun.tools.jdi.LinkedHashMap

Summary

Public Constructors
LinkedHashMap(int initialCapacity, float loadFactor)
Constructs a new, empty LinkedHashMap with the specified initial capacity and the specified load factor.
LinkedHashMap(int initialCapacity)
Constructs a new, empty LinkedHashMap with the specified initial capacity and default load factor.
LinkedHashMap()
Constructs a new, empty LinkedHashMap with a default capacity and load factor.
LinkedHashMap(Map t)
Constructs a new LinkedHashMap with the same mappings as the given Map.
Public Methods
void clear()
Removes all mappings from this LinkedHashMap.
Object clone()
Returns a shallow copy of this LinkedHashMap.
boolean containsKey(Object key)
Returns true if this LinkedHashMap contains a mapping for the specified key.
boolean containsValue(Object value)
Returns true if this LinkedHashMap maps one or more keys to the specified value.
Set entrySet()
Returns a Collection view of the mappings contained in this LinkedHashMap.
boolean equals(Object o)
Compares the specified Object with this Map for equality.
Object get(Object key)
Returns the value to which this LinkedHashMap maps the specified key.
int indexOf(Object key)
Returns the position of the mapping for the specified key in the ordered map.
boolean isEmpty()
Returns true if this Map contains no key-value mappings.
Set keySet()
Returns a Set view of the keys contained in this LinkedHashMap.
Object put(int index, Object key, Object value)
Associates the specified value with the specified key in this LinkedHashMap and position the mapping at the specified index.
Object put(Object key, Object value)
Associates the specified value with the specified key in this LinkedHashMap.
void putAll(Map t)
Copies all of the mappings from the specified Map to this LinkedHashMap These mappings will replace any mappings that this LinkedHashMap had for any of the keys currently in the specified Map.
Object remove(Object key)
Removes the mapping for this key from this LinkedHashMap if present.
int size()
Returns the number of key-value mappings in this Map.
Collection values()
Returns a Collection view of the values contained in this LinkedHashMap.
[Expand]
Inherited Methods
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map

Public Constructors

public LinkedHashMap (int initialCapacity, float loadFactor)

Constructs a new, empty LinkedHashMap with the specified initial capacity and the specified load factor.

Parameters
initialCapacity the initial capacity of the LinkedHashMap.
loadFactor a number between 0.0 and 1.0.
Throws
IllegalArgumentException if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero.

public LinkedHashMap (int initialCapacity)

Constructs a new, empty LinkedHashMap with the specified initial capacity and default load factor.

Parameters
initialCapacity the initial capacity of the LinkedHashMap.

public LinkedHashMap ()

Constructs a new, empty LinkedHashMap with a default capacity and load factor.

public LinkedHashMap (Map t)

Constructs a new LinkedHashMap with the same mappings as the given Map. The LinkedHashMap is created with a capacity of thrice the number of mappings in the given Map or 11 (whichever is greater), and a default load factor.

Public Methods

public void clear ()

Removes all mappings from this LinkedHashMap.

public Object clone ()

Returns a shallow copy of this LinkedHashMap. The keys and values themselves are not cloned.

Returns
  • a shallow copy of this map

public boolean containsKey (Object key)

Returns true if this LinkedHashMap contains a mapping for the specified key.

Parameters
key key whose presence in this Map is to be tested.
Returns
  • true if this map contains a mapping for the specified key

public boolean containsValue (Object value)

Returns true if this LinkedHashMap maps one or more keys to the specified value.

Parameters
value value whose presence in this Map is to be tested.
Returns
  • true if this map maps one or more keys to the specified value

public Set entrySet ()

Returns a Collection view of the mappings contained in this LinkedHashMap. Each element in the returned collection is a Map.Entry. The Collection is backed by the LinkedHashMap, so changes to the LinkedHashMap are reflected in the Collection, and vice-versa. The Collection supports element removal, which removes the corresponding mapping from the LinkedHashMap, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns
  • a set view of the mappings contained in this map
See Also

public boolean equals (Object o)

Compares the specified Object with this Map for equality. Returns true if the given object is also a LinkedHashMap and the two Maps represent the same mappings in the same order. More formally, two Maps t1 and t2 represent the same mappings if t1.keySet().equals(t2.keySet()) and for every key k in t1.keySet(), (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) .

This implementation first checks if the specified Object is this Map; if so it returns true. Then, it checks if the specified Object is a Map whose size is identical to the size of this Set; if not, it it returns false. If so, it iterates over this Map and the specified Map's entrySet() Collection, and checks that the specified Map contains each mapping that this Map contains at the same position. If the specified Map fails to contain such a mapping in the right order, false is returned. If the iteration completes, true is returned.

Parameters
o Object to be compared for equality with this Map.
Returns
  • true if the specified Object is equal to this Map.

public Object get (Object key)

Returns the value to which this LinkedHashMap maps the specified key. Returns null if the LinkedHashMap contains no mapping for this key. A return value of null does not necessarily indicate that the LinkedHashMap contains no mapping for the key; it's also possible that the LinkedHashMap explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
key key whose associated value is to be returned.
Returns
  • the value to which the specified key is mapped, or null if this map contains no mapping for the key

public int indexOf (Object key)

Returns the position of the mapping for the specified key in the ordered map.

Parameters
key the specified key.
Returns
  • index of the key mapping.

public boolean isEmpty ()

Returns true if this Map contains no key-value mappings.

Returns
  • true if this map contains no key-value mappings

public Set keySet ()

Returns a Set view of the keys contained in this LinkedHashMap. The Set is backed by the LinkedHashMap, so changes to the LinkedHashMap are reflected in the Set, and vice-versa. The Set supports element removal, which removes the corresponding mapping from the LinkedHashMap, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

Returns
  • a set view of the keys contained in this map

public Object put (int index, Object key, Object value)

Associates the specified value with the specified key in this LinkedHashMap and position the mapping at the specified index. If the LinkedHashMap previously contained a mapping for this key, the old value is replaced and the position of this mapping entry in the double linked list remains the same. Otherwise, a new mapping entry is created and inserted into the list at the specified position.

Parameters
index the position to put the key-value mapping.
key key with which the specified value is to be associated.
value value to be associated with the specified key.
Returns
  • previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the LinkedHashMap previously associated null with the specified key.

public Object put (Object key, Object value)

Associates the specified value with the specified key in this LinkedHashMap. If the LinkedHashMap previously contained a mapping for this key, the old value is replaced. The mapping entry is also appended to the end of the ordered linked list.

Parameters
key key with which the specified value is to be associated.
value value to be associated with the specified key.
Returns
  • previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the LinkedHashMap previously associated null with the specified key.

public void putAll (Map t)

Copies all of the mappings from the specified Map to this LinkedHashMap These mappings will replace any mappings that this LinkedHashMap had for any of the keys currently in the specified Map.

Parameters
t Mappings to be stored in this Map.

public Object remove (Object key)

Removes the mapping for this key from this LinkedHashMap if present. The mapping would also be removed from the double linked list.

Parameters
key key whose mapping is to be removed from the Map.
Returns
  • previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the LinkedHashMap previously associated null with the specified key.

public int size ()

Returns the number of key-value mappings in this Map.

Returns
  • the number of key-value mappings in this map

public Collection values ()

Returns a Collection view of the values contained in this LinkedHashMap. The Collection is backed by the LinkedHashMap, so changes to the LinkedHashMap are reflected in the Collection, and vice-versa. The Collection supports element removal, which removes the corresponding mapping from the LinkedHashMap, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns
  • a collection view of the values contained in this map