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
|
void
|
clear()
Removes all mappings from this HashMap, leaving it empty.
|
|
Object
|
clone()
Returns a new HashMap with the same mappings and size as this HashMap.
|
|
boolean
|
containsKey(Object key)
Searches this HashMap for the specified key.
|
|
boolean
|
containsValue(Object value)
Searches this HashMap for the specified value.
|
|
Set<Entry<K, V>>
|
entrySet()
Returns a Set of the mappings contained in this HashMap.
|
|
V
|
get(Object key)
Returns the value of the mapping with the specified key.
|
|
boolean
|
isEmpty()
Returns if this HashMap has no elements, a size of zero.
|
|
Set<K>
|
keySet()
Returns a Set of the keys contained in this HashMap.
|
|
V
|
put(K key, V value)
Maps the specified key to the specified value.
|
|
void
|
putAll(Map<? extends K, ? extends V> map)
Copies all the mappings in the given map to this map.
|
|
V
|
remove(Object key)
Removes a mapping with the specified key from this HashMap.
|
|
int
|
size()
Returns the number of mappings in this HashMap.
|
|
Collection<V>
|
values()
Returns a Collection of the values contained in this HashMap.
|
|
From class java.util.AbstractMap
|
void
|
clear()
Removes all elements from this Map, leaving it empty.
|
|
Object
|
clone()
Returns a new instance of the same class as the receiver, whose slots
have been filled in with the values in the slots of the receiver.
|
|
boolean
|
containsKey(Object key)
Searches this Map for the specified key.
|
|
boolean
|
containsValue(Object value)
Searches this Map for the specified value.
|
|
abstract
Set<Entry<K, V>>
|
entrySet()
Returns a set view of the mappings contained in this map.
|
|
boolean
|
equals(Object object)
Compares the specified object to this Map and answer if they are equal.
|
|
V
|
get(Object key)
Returns the value of the mapping with the specified key.
|
|
int
|
hashCode()
Returns an integer hash code for the receiver.
|
|
boolean
|
isEmpty()
Returns if this Map has no elements, a size of zero.
|
|
Set<K>
|
keySet()
Returns a Set of the keys contained in this Map.
|
|
V
|
put(K key, V value)
Maps the specified key to the specified value.
|
|
void
|
putAll(Map<? extends K, ? extends V> map)
Copies every mapping in the specified Map to this Map.
|
|
V
|
remove(Object key)
Removes a mapping with the specified key from this Map.
|
|
int
|
size()
Returns the number of elements in this Map.
|
|
String
|
toString()
Returns the string representation of this Map.
|
|
Collection<V>
|
values()
Returns a collection of the values contained in this map.
|
|
From class java.lang.Object
|
Object
|
clone()
Returns a new instance of the same class as the receiver, whose slots
have been filled in with the values in the slots of the receiver.
|
|
boolean
|
equals(Object o)
Compares the argument to the receiver, and returns true if they represent
the same object using a class specific comparison.
|
|
void
|
finalize()
Called by the virtual machine when there are no longer any (non-weak)
references to the receiver.
|
|
final
Class<? extends Object>
|
getClass()
Returns the unique instance of java.lang.Class which represents the class
of the receiver.
|
|
int
|
hashCode()
Returns an integer hash code for the receiver.
|
|
final
void
|
notify()
Causes one thread which is wait ing on the receiver to be
made ready to run.
|
|
final
void
|
notifyAll()
Causes all threads which are wait ing on the receiver to
be made ready to run.
|
|
String
|
toString()
Returns a string containing a concise, human-readable description of the
receiver.
|
|
final
void
|
wait(long time, int frac)
Causes the thread which sent this message to be made not ready to run
either pending some change in the receiver (as indicated by
notify or notifyAll) or the expiration of
the timeout.
|
|
final
void
|
wait(long time)
Causes the thread which sent this message to be made not ready to run
either pending some change in the receiver (as indicated by
notify or notifyAll) or the expiration of
the timeout.
|
|
final
void
|
wait()
Causes the thread which sent this message to be made not ready to run
pending some change in the receiver (as indicated by notify
or notifyAll).
|
|
From interface java.util.Map
|
abstract
void
|
clear()
Removes all elements from this Map, leaving it empty.
|
|
abstract
boolean
|
containsKey(Object key)
Searches this Map for the specified key.
|
|
abstract
boolean
|
containsValue(Object value)
Searches this Map for the specified value.
|
|
abstract
Set<Entry<K, V>>
|
entrySet()
Returns a Set whose elements comprise all of the mappings
that are to be found in this Map.
|
|
abstract
boolean
|
equals(Object object)
Compares the argument to the receiver, and returns true if they represent
the same object using a class specific comparison.
|
|
abstract
V
|
get(Object key)
Returns the value of the mapping with the specified key.
|
|
abstract
int
|
hashCode()
Returns an integer hash code for the receiver.
|
|
abstract
boolean
|
isEmpty()
Returns if this Map has no elements, a size of zero.
|
|
abstract
Set<K>
|
keySet()
Returns a Set of the keys contained in this Map.
|
|
abstract
V
|
put(K key, V value)
Maps the specified key to the specified value.
|
|
abstract
void
|
putAll(Map<? extends K, ? extends V> map)
Copies every mapping in the specified Map to this Map.
|
|
abstract
V
|
remove(Object key)
Removes a mapping with the specified key from this Map.
|
|
abstract
int
|
size()
Returns the number of elements in this Map.
|
|
abstract
Collection<V>
|
values()
Returns all of the current Map values in a
Collection.
|
|
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