java.util.LinkedHashMap<K, V>
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
Public Methods
Protected Methods
clear,
clone,
containsKey,
containsValue,
entrySet,
get,
isEmpty,
keySet,
put,
putAll,
remove,
size,
values
clear,
clone,
containsKey,
containsValue,
entrySet,
equals,
get,
hashCode,
isEmpty,
keySet,
put,
putAll,
remove,
size,
toString,
values
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Methods inherited
from interface
java.util.Map
clear,
containsKey,
containsValue,
entrySet,
equals,
get,
hashCode,
isEmpty,
keySet,
put,
putAll,
remove,
size,
values
Details
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
Public Methods
public
void
clear()
Removes all mappings from this HashMap, leaving it empty.
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.
public
V
get(Object key)
Retrieve the map value corresponding to the given key.
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.
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.
Returns
- the value associated with the key or null if the key was no in
the map
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