Map<K,V>public final class LightweightMap<K,V> extends Object implements Map<K,V>
Map interfaces.
The LightweightMap container uses less memory than the HashMap container,
but may show poor performance when reaching a large size.
It is recommended that you use this container when less memory is required.
Note: The thread is secure only when data is read from the LightweightMap container.
| 构造器 | 说明 |
|---|---|
LightweightMap() |
Constructs a default
LightweightMap container. |
LightweightMap(int capacity) |
Constructs an
LightweightMap container with a specified capacity. |
LightweightMap(int capacity,
boolean useIdentityHash) |
Constructs an
LightweightMap container with a specified capacity and
specifies whether to use the system hash method. |
LightweightMap(LightweightMap<? extends K,? extends V> srcLightweightMap) |
Constructs a new
LightweightMap container using an existing LightweightMap container. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
clear() |
Deletes all key-value pair mappings in an
LightweightMap container. |
boolean |
containsAll(Collection<?> collection) |
Checks whether an
LightweightMap container has all the objects in a specified Collection object. |
boolean |
containsKey(Object key) |
Checks whether an
LightweightMap container has a key that is the same as a specified key. |
boolean |
containsValue(Object value) |
Checks whether an
LightweightMap container has a value that is the same as a specified value. |
void |
ensureCapacity(int minimumCapacity) |
Ensures that the capacity of an
LightweightMap container is greater than or equal
to a specified value, and that the container has all the original objects after capacity expansion. |
Set<Map.Entry<K,V>> |
entrySet() |
Obtains a
Set object that contains all key-value pairs in an LightweightMap container. |
V |
get(Object key) |
Obtains the value equal to a specified
key in an LightweightMap container. |
int |
indexOfKey(Object key) |
Obtains the
index of the key equal to a specified key in an LightweightMap container. |
int |
indexOfValue(Object value) |
Obtains the
index of the value equal to a specified value in an LightweightMap container. |
boolean |
isEmpty() |
Checks whether an
LightweightMap container has no key-value pair. |
K |
keyAt(int index) |
Obtains the key at the location identified by
index in an LightweightMap container. |
Set<K> |
keySet() |
Obtains a
Set object that contains all the keys of an LightweightMap container. |
V |
put(K key,
V value) |
Saves a key-value pair to an
LightweightMap container. |
void |
putAll(Map<? extends K,? extends V> map) |
Adds all objects of a specified
Map container to an LightweightMap container. |
void |
putAll(LightweightMap<? extends K,? extends V> arrayMap) |
Adds all objects of a specified
LightweightMap container to another LightweightMap container. |
V |
remove(Object key) |
Deletes a key-value pair whose key is the same as a specified
key from an LightweightMap
container. |
boolean |
removeAll(Collection<?> collection) |
Deletes key-value pairs with the same objects as a specified
Collection
from an LightweightMap container. |
V |
removeAt(int index) |
Deletes a key-value pair at the location identified by
index from an LightweightMap container. |
boolean |
retainAll(Collection<?> collection) |
Deletes the key-value pairs that do not exist in a specified
Collection object
from an LightweightMap container. |
V |
setValueAt(int index,
V value) |
Sets the value identified by
index in an LightweightMap container to a specified value. |
int |
size() |
Obtains the number of key-value pairs stored in an
LightweightMap container. |
String |
toString() |
Obtains a string that contains all the keys and values in an
LightweightMap container. |
V |
valueAt(int index) |
Obtains the value identified by
index in an LightweightMap container. |
Collection<V> |
values() |
Obtains a
Collection object that contains all values of an LightweightMap container. |
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic LightweightMap()
LightweightMap container.public LightweightMap(int capacity)
LightweightMap container with a specified capacity.
The number of key-value pairs of the constructed LightweightMap container can hold
is determined by the specified capacity.
capacity - Indicates the capacity of the LightweightMap container to be constructed.public LightweightMap(int capacity,
boolean useIdentityHash)
LightweightMap container with a specified capacity and
specifies whether to use the system hash method.capacity - Indicates the capacity of the LightweightMap container to be constructed.useIdentityHash - Specifies whether the system hash method is used to map keys.
The value true indicates that the System.identityHashCode method is used.
The value false indicates that the default hashCode method is used.public LightweightMap(LightweightMap<? extends K,? extends V> srcLightweightMap)
LightweightMap container using an existing LightweightMap container.srcLightweightMap - Indicates an existing LightweightMap container.public void clear()
LightweightMap container.
This method makes the LightweightMap container empty.
public boolean containsAll(Collection<?> collection)
LightweightMap container has all the objects in a specified Collection object.collection - Indicates the specified Collection object.true if the LightweightMap container has all the objects
in the specified Collection object;
returns false otherwise.NullPointerException - Throws this exception if collection is null.public boolean containsKey(Object key)
LightweightMap container has a key that is the same as a specified key.containsKey 在接口中 Map<K,V>key - Indicates the specified key.true if the LightweightMap container has a key
that is the same as the specified key;
returns false otherwise.public boolean containsValue(Object value)
LightweightMap container has a value that is the same as a specified value.containsValue 在接口中 Map<K,V>value - Indicates the specified value.true if the LightweightMap container has a value
that is the same as the specified value;
returns false otherwise.public void ensureCapacity(int minimumCapacity)
LightweightMap container is greater than or equal
to a specified value, and that the container has all the original objects after capacity expansion.minimumCapacity - Indicates the minimum capacity allowed for the LightweightMap container.public V get(Object key)
key in an LightweightMap container.public int indexOfKey(Object key)
index of the key equal to a specified key in an LightweightMap container.key - Indicates the specified key.index in int format.public int indexOfValue(Object value)
index of the value equal to a specified value in an LightweightMap container.value - Indicates the specified value.index in int format.public boolean isEmpty()
LightweightMap container has no key-value pair.public K keyAt(int index)
index in an LightweightMap container.
If index is a negative number, the key is located from the reverse direction.
index - Identifies the location of a key.index in the LightweightMap container.public Set<K> keySet()
Set object that contains all the keys of an LightweightMap container.public V put(K key, V value)
LightweightMap container.
If the key of the key-value pair already exists in the LightweightMap container,
the existing value of the key is overwritten by the new value.
If the capacity of the LightweightMap container has been used up, it will be automatically expanded.
put 在接口中 Map<K,V>key - Indicates the key of the key-value pair to be saved.value - Indicates the value of the key-value pair to be saved.key before this operation is performed;
returns null if the key is not contained in the LightweightMap container.public void putAll(LightweightMap<? extends K,? extends V> arrayMap)
LightweightMap container to another LightweightMap container.arrayMap - Indicates the specified LightweightMap container
whose objects are to be added to another LightweightMap container.NullPointerException - Throws this exception if arrayMap is null.public void putAll(Map<? extends K,? extends V> map)
Map container to an LightweightMap container.putAll 在接口中 Map<K,V>map - Indicates the specified Map container
whose objects are to be added to the LightweightMap container.NullPointerException - Throws this exception if map is null.public V remove(Object key)
key from an LightweightMap
container.public boolean removeAll(Collection<?> collection)
Collection
from an LightweightMap container.collection - Indicates the specified Collection which defines the mappings to be deleted.true if any object is deleted from the LightweightMap container;
returns false otherwise.NullPointerException - Throws this exception if collection is null.public V removeAt(int index)
index from an LightweightMap container.
If index is a negative number, the key-value pair is located from the reverse direction.
During the deletion, the system determines whether to expand or reduce capacity
of the LightweightMap container. If the number of objects in the container is less
than a specified number, the system reduces the capacity of the container.
index - Identifies the location of a key-value pair.index.public boolean retainAll(Collection<?> collection)
Collection object
from an LightweightMap container.collection - Indicates the specified Collection object.true if any key-value pair is deleted from the LightweightMap container;
returns false otherwise.NullPointerException - Throws this exception if collection is null.public V setValueAt(int index, V value)
index in an LightweightMap container to a specified value.index - Identifies the location of a value.value - Indicates the value to be set.index.IndexOutOfBoundsException - Throws this exception if the specified index is beyond the valid range.public int size()
LightweightMap container.public String toString()
LightweightMap container.
An example string is "{1: "one", 2: "two"}".
The keys and values must support the toString method.
public V valueAt(int index)
index in an LightweightMap container.
If index is a negative number, the value is located from the reverse direction.
index - Identifies the location of a value.index.public Collection<V> values()
Collection object that contains all values of an LightweightMap container.values 在接口中 Map<K,V>Collection object that contains all values of an LightweightMap container.