加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090218033257/http://developer.android.com:80/reference/java/util/LinkedHashMap.html
public class

LinkedHashMap

extends HashMap<K, V>
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ java.util.HashMap<K, V>
       ↳ java.util.LinkedHashMap<K, V>

Class Overview

LinkedHashMap is a variant on HashMap. Its entries are kept in a doubly-linked list. The iteration order is, by default, the order in which keys were inserted.

If the three argument constructor is used, and order is specified as true, the iteration would be in the order that entries were accessed. The access order gets affected by put(), get(), putAll() operations, but not by operations on the collection views.

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

Summary

Public Constructors
LinkedHashMap()
Constructs a new empty instance of LinkedHashMap.
LinkedHashMap(int s)
Constructor with specified size.
LinkedHashMap(int s, float lf)
Constructor with specified size and load factor.
LinkedHashMap(int s, float lf, boolean order)
Constructor with specified size, load factor and access order
LinkedHashMap(Map<? extends K, ? extends V> m)
Constructor with input map
Public Methods
void clear()
Removes all mappings from this HashMap, leaving it empty.
Set<Entry<K, V>> entrySet()
Returns a Set of the mappings contained in this HashMap.
V get(Object key)
Retrieve the map value corresponding to the given key.
Set<K> keySet()
Returns a Set of the keys contained in this HashMap.
V put(K key, V value)
Set the mapped value for the given key to the given value.
V remove(Object key)
Remove the entry corresponding to the given key.
Collection<V> values()
Returns a Collection of the values contained in this HashMap.
Protected Methods
boolean removeEldestEntry(Entry<K, V> eldest)
This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member.
[Expand]
Inherited Methods
From class java.util.HashMap
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map

Public Constructors

public LinkedHashMap ()

Constructs a new empty instance of LinkedHashMap.

public LinkedHashMap (int s)

Constructor with specified size.

Parameters
s Size of LinkedHashMap required

public LinkedHashMap (int s, float lf)

Constructor with specified size and load factor.

Parameters
s Size of LinkedHashMap required
lf Load factor

public LinkedHashMap (int s, float lf, boolean order)

Constructor with specified size, load factor and access order

Parameters
s Size of LinkedHashmap required
lf Load factor
order If true indicates that traversal order should begin with most recently accessed

public LinkedHashMap (Map<? extends K, ? extends V> m)

Constructor with input map

Parameters
m Input map

Public Methods

public void clear ()

Removes all mappings from this HashMap, leaving it empty.

See Also

public Set<Entry<K, V>> entrySet ()

Returns a Set of the mappings contained in this HashMap. Each element in the set is a Map.Entry. The set is backed by this HashMap so changes to one are reflected by the other. The set does not support adding.

Returns
  • a Set of the mappings

public V get (Object key)

Retrieve the map value corresponding to the given key.

Parameters
key Key value
Returns
  • mapped value or null if the key is not in the map

public Set<K> keySet ()

Returns a Set of the keys contained in this HashMap. The set is backed by this HashMap so changes to one are reflected by the other. The set does not support adding.

Returns
  • a Set of the keys

public V put (K key, V value)

Set the mapped value for the given key to the given value.

Parameters
key Key value
value New mapped value
Returns
  • The old value if the key was already in the map or null otherwise.

public V remove (Object key)

Remove the entry corresponding to the given key.

Parameters
key the key
Returns
  • the value associated with the key or null if the key was no in the map

public Collection<V> values ()

Returns a Collection of the values contained in this HashMap. The collection is backed by this HashMap so changes to one are reflected by the other. The collection does not support adding.

Returns
  • a Collection of the values

Protected Methods

protected boolean removeEldestEntry (Entry<K, V> eldest)

This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member. If this map was created with accessOrder = true, then the result of removeEldesrEntry is assumed to be false.

Returns
  • true if the eldest member should be removed