public class ConcurrentHashMap
extends AbstractMap<K, V> implements ConcurrentMap<K, V>, Serializable
| java.lang.Object | ||
| ↳ | java.util.AbstractMap<K, V> | |
| ↳ | java.util.concurrent.ConcurrentHashMap<K, V> | |
哈希表支持检索的完全并发和更新的高预期并发。 该类遵循与Hashtable相同的功能规范,并且包括与Hashtable每个方法相对应的方法版本。 但是,即使所有操作都是线程安全的,检索操作也不需要锁定,并且也不支持以阻止所有访问的方式锁定整个表。 这个类在Hashtable中与依赖其线程安全性的程序完全可互操作,但不依赖其同步细节。
检索操作(包括get )通常不会阻止,因此可能与更新操作(包括put和remove )重叠。 检索反映了最近完成的更新操作的结果。 (更正式地说,对于给定键的更新操作承担与该键的任何(非空)检索报告更新值的发生之前关系。)对于诸如putAll和clear类的聚合操作,并发检索可以反映插入或移除只有一些条目。 类似地,Iterators,Spliterator和Enumerations在创建迭代器/枚举时或之后返回反映哈希表状态的元素。 他们不扔ConcurrentModificationException 。 但是,迭代器被设计为一次只能由一个线程使用。 请记住,骨料状态方法的结果,包括size , isEmpty ,并containsValue通常是有用的,只有当一个地图没有发生在其他线程并发更新。 否则,这些方法的结果反映了可能足以用于监视或估计目的的暂态,但不适用于程序控制。
当碰撞太多时(即,具有不同哈希码但落入与表格大小相同的时隙的密钥),表格会动态扩展,预期的平均效果是每个映射保持大约两个bin(对应于0.75个负载调整大小的因素阈值)。 随着映射的添加和删除,这个平均值可能会有很大的变化,但总的来说,这保持了散列表通常公认的时间/空间折衷。 但是,调整这个或任何其他类型的哈希表可能是一个相对较慢的操作。 如果可能,最好提供一个尺寸估计值作为可选的initialCapacity构造函数参数。 一个额外的可选loadFactor构造函数参数提供了另一种定制初始表容量的方法,方法是指定要用于计算给定数量的元素的空间分配量的表密度。 此外,为了与此类的以前版本兼容,构造函数可以选择指定预期的concurrencyLevel作为内部大小调整的附加提示。 请注意,使用与hashCode()完全相同的许多密钥是降低任何散列表性能的一种可靠方法。 为了改善影响,当键是Comparable ,这个类可以使用键之间的比较顺序来帮助断开关系。
甲 Set投影一个的ConcurrentHashMap可以(使用被创建 newKeySet()或 newKeySet(int) ),或观察(使用 keySet(Object)时仅键是感兴趣的,并且被映射的值是(可能瞬时)不使用或全部取相同的映射值。
通过使用LongAdder值并通过computeIfAbsent初始化,ConcurrentHashMap可用作可伸缩频率映射(直方图或多重集的一种形式)。 例如,要将计数添加到ConcurrentHashMap<String,LongAdder> freqs ,可以使用freqs.computeIfAbsent(key, k -> new LongAdder()).increment();
这个类及其视图和迭代器实现了 Map和 Iterator接口的所有 可选方法。
像 Hashtable但不像 HashMap ,此类 不允许 null用作键或值。
ConcurrentHashMaps支持一系列顺序和并行批量操作,与大多数Stream方法不同,该操作被设计为安全并且经常理智地应用于即使由其他线程同时更新的映射; 例如,在计算共享注册表中值的快照摘要时。 有三种操作,每种都有四种形式,接受带有键,值,条目和(键,值)对的函数作为参数和/或返回值。 因为ConcurrentHashMap的元素没有以任何特定的方式排序,并且可能在不同的并行执行中以不同的顺序处理,所以提供的函数的正确性不应取决于任何排序,或者任何其他可能暂时更改的对象或值计算正在进行中; 除了for each action,理想情况下应该是无副作用的。 对Map.Entry对象的批量操作不支持方法setValue 。
这些批量操作接受一个parallelismThreshold论点。 如果当前地图大小估计小于给定阈值,则方法顺序进行。 使用值Long.MAX_VALUE抑制所有并行性。 使用1的值通过划分为足够的子任务以充分利用用于所有并行计算的commonPool() , 1最大的并行性。 通常情况下,您最初会选择这些极端值中的一个,然后衡量使用中间开销与吞吐量之间的值的性能。
批量操作的并发属性来自ConcurrentHashMap:从get(key)返回的任何非空结果,并且相关的访问方法与关联的插入或更新相关联。 任何批量操作的结果反映了这些每元素关系的组成(但不一定关于整个地图是原子的,除非它以某种方式知道是静止的)。 相反,因为映射中的键和值永远不为null,所以null作为当前缺少任何结果的可靠原子指标。 为了保持这个属性,null作为所有非标量约简操作的隐含基础。 对于double,long和int版本,基础应该与其他任何值结合时返回其他值(更正式地说,它应该是减少的标识元素)。 最常见的削减有这些属性; 例如,用基础MAX_VALUE计算基数为0或最小值的和。
作为参数提供的搜索和转换函数应该类似地返回null来指示缺少任何结果(在这种情况下,它不被使用)。 在映射缩减的情况下,这也使得变换能够用作过滤器,如果不应该组合该元素,则返回null(或者在原始专门化的情况下,基于身份的基础)。 在搜索或缩减操作中使用它们之前,您可以通过在“null意味着现在没有任何东西”规则下自己组合它们来创建复合转换和过滤。
接受和/或返回Entry参数的方法维护键值关联。 例如,当找到最大价值的钥匙时,它们可能很有用。 请注意,可以使用new AbstractMap.SimpleEntry(k,v)提供“普通”条目参数。
批量操作可能会突然完成,引发应用程序中遇到的异常。 请记住,在处理这样的异常时,其他并发执行的函数也可能引发异常,或者如果第一次异常没有发生,就会这样做。
与顺序形式相比,并行加速是常见的,但不能保证。 如果并行计算的基础工作比计算本身更昂贵,那么涉及小地图上的简短函数的并行操作可能比顺序形式执行更慢。 同样,如果所有处理器都忙于执行不相关的任务,并行化可能不会导致太多的实际并行性。
所有任务方法的所有参数都必须是非空的。
Nested classes |
|
|---|---|
class |
ConcurrentHashMap.KeySetView<K, V> 将ConcurrentHashMap视图作为键的 |
Public constructors |
|
|---|---|
ConcurrentHashMap() 使用默认的初始表格大小(16)创建一个新的空白地图。 |
|
ConcurrentHashMap(int initialCapacity) 创建一个新的空映射,其初始表大小可容纳指定数量的元素,而无需动态调整大小。 |
|
ConcurrentHashMap(Map<? extends K, ? extends V> m) 使用与给定映射相同的映射创建新映射。 |
|
ConcurrentHashMap(int initialCapacity, float loadFactor) 根据给定的元素数量( |
|
ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel) 创建具有基于给定数量的元件(初始表大小的新的空映射 |
|
Public methods |
|
|---|---|
void |
clear() 从此映射中移除所有映射。 |
V |
compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) 尝试计算指定键和其当前映射值的映射(如果没有当前映射, |
V |
computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) 如果指定的键尚未与值相关联,则尝试使用给定的映射函数计算其值,并将其输入到此映射中,除非 |
V |
computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) 如果指定键的值存在,则尝试计算给定键和其当前映射值的新映射。 |
boolean |
contains(Object value) 测试某些键是否映射到此表中的指定值。 |
boolean |
containsKey(Object key) 测试指定的对象是否是此表中的键。 |
boolean |
containsValue(Object value) 如果此映射将一个或多个键映射到指定值,则返回 |
Enumeration<V> |
elements() 返回此表中值的枚举。 |
Set<Entry<K, V>> |
entrySet() 返回此映射中映射的映射的 |
boolean |
equals(Object o) 将指定的对象与此映射进行比较以获得相等性。 |
void |
forEach(BiConsumer<? super K, ? super V> action) 对此映射中的每个条目执行给定操作,直到处理完所有条目或操作抛出异常为止。 |
void |
forEach(long parallelismThreshold, BiConsumer<? super K, ? super V> action) 对每个(键,值)执行给定的操作。 |
<U> void |
forEach(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> transformer, Consumer<? super U> action) 对每个(键,值)的每个非空变换执行给定的操作。 |
<U> void |
forEachEntry(long parallelismThreshold, Function<Entry<K, V>, ? extends U> transformer, Consumer<? super U> action) 对每个条目的每个非空转换执行给定的操作。 |
void |
forEachEntry(long parallelismThreshold, Consumer<? super Entry<K, V>> action) 为每个条目执行给定的操作。 |
<U> void |
forEachKey(long parallelismThreshold, Function<? super K, ? extends U> transformer, Consumer<? super U> action) 对每个键的每个非空转换执行给定的操作。 |
void |
forEachKey(long parallelismThreshold, Consumer<? super K> action) 对每个键执行给定的操作。 |
<U> void |
forEachValue(long parallelismThreshold, Function<? super V, ? extends U> transformer, Consumer<? super U> action) 对每个值的每个非空变换执行给定的操作。 |
void |
forEachValue(long parallelismThreshold, Consumer<? super V> action) 对每个值执行给定的操作。 |
V |
get(Object key) 返回指定键映射到的值,如果此映射不包含键映射,则返回 |
V |
getOrDefault(Object key, V defaultValue) 返回指定键映射到的值,或者如果此映射不包含键映射,则返回给定的默认值。 |
int |
hashCode() 返回此 |
boolean |
isEmpty() 如果此映射不包含键 - 值映射,则返回 该实现返回 size() == 0 。 |
Set<K> |
keySet() 返回此映射中包含的键的 |
KeySetView<K, V> |
keySet(V mappedValue) 使用给定的公共映射值( |
Enumeration<K> |
keys() 返回此表中键的枚举。 |
long |
mappingCount() 返回映射的数量。 |
V |
merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) 如果指定的键尚未与(非空)值相关联,则将其与给定值相关联。 |
static <K> KeySetView<K, Boolean> |
newKeySet() 创建一个由给定类型的ConcurrentHashMap支持的新的 |
static <K> KeySetView<K, Boolean> |
newKeySet(int initialCapacity) 创建一个由给定类型的ConcurrentHashMap支持的新的 |
V |
put(K key, V value) 将指定的键映射到此表中的指定值。 |
void |
putAll(Map<? extends K, ? extends V> m) 将指定映射中的所有映射复制到此映射。 |
V |
putIfAbsent(K key, V value) 如果指定的键尚未与值相关联,则将其与给定值相关联。 |
<U> U |
reduce(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> transformer, BiFunction<? super U, ? super U, ? extends U> reducer) 返回使用给定的缩减器合并值累积所有(键,值)对的给定变换的结果,如果不是,则返回null。 |
Entry<K, V> |
reduceEntries(long parallelismThreshold, BiFunction<Entry<K, V>, Entry<K, V>, ? extends Entry<K, V>> reducer) 返回使用给定reducer合并值的所有条目的累积结果,如果没有,则返回null。 |
<U> U |
reduceEntries(long parallelismThreshold, Function<Entry<K, V>, ? extends U> transformer, BiFunction<? super U, ? super U, ? extends U> reducer) 返回使用给定缩减器合并值累积给定转换的结果,如果没有,则返回null。 |
double |
reduceEntriesToDouble(long parallelismThreshold, ToDoubleFunction<Entry<K, V>> transformer, double basis, DoubleBinaryOperator reducer) 返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。 |
int |
reduceEntriesToInt(long parallelismThreshold, ToIntFunction<Entry<K, V>> transformer, int basis, IntBinaryOperator reducer) 返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。 |
long |
reduceEntriesToLong(long parallelismThreshold, ToLongFunction<Entry<K, V>> transformer, long basis, LongBinaryOperator reducer) 返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。 |
K |
reduceKeys(long parallelismThreshold, BiFunction<? super K, ? super K, ? extends K> reducer) 返回使用给定缩减器合并值累积所有键的结果,如果没有,则返回null。 |
<U> U |
reduceKeys(long parallelismThreshold, Function<? super K, ? extends U> transformer, BiFunction<? super U, ? super U, ? extends U> reducer) 返回使用给定的缩减器合并值累加给定所有键的转换的结果,如果没有,则返回null。 |
double |
reduceKeysToDouble(long parallelismThreshold, ToDoubleFunction<? super K> transformer, double basis, DoubleBinaryOperator reducer) 返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。 |
int |
reduceKeysToInt(long parallelismThreshold, ToIntFunction<? super K> transformer, int basis, IntBinaryOperator reducer) 返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。 |
long |
reduceKeysToLong(long parallelismThreshold, ToLongFunction<? super K> transformer, long basis, LongBinaryOperator reducer) 返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。 |
double |
reduceToDouble(long parallelismThreshold, ToDoubleBiFunction<? super K, ? super V> transformer, double basis, DoubleBinaryOperator reducer) 返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。 |
int |
reduceToInt(long parallelismThreshold, ToIntBiFunction<? super K, ? super V> transformer, int basis, IntBinaryOperator reducer) 返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。 |
long |
reduceToLong(long parallelismThreshold, ToLongBiFunction<? super K, ? super V> transformer, long basis, LongBinaryOperator reducer) 返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。 |
V |
reduceValues(long parallelismThreshold, BiFunction<? super V, ? super V, ? extends V> reducer) 返回使用给定缩减器合并值累加所有值的结果,如果没有,则返回null。 |
<U> U |
reduceValues(long parallelismThreshold, Function<? super V, ? extends U> transformer, BiFunction<? super U, ? super U, ? extends U> reducer) 返回使用给定的缩减器合并值累积所有值的给定变换的结果,如果没有,则返回null。 |
double |
reduceValuesToDouble(long parallelismThreshold, ToDoubleFunction<? super V> transformer, double basis, DoubleBinaryOperator reducer) 返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。 |
int |
reduceValuesToInt(long parallelismThreshold, ToIntFunction<? super V> transformer, int basis, IntBinaryOperator reducer) 返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。 |
long |
reduceValuesToLong(long parallelismThreshold, ToLongFunction<? super V> transformer, long basis, LongBinaryOperator reducer) 返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。 |
V |
remove(Object key) 从此映射中删除键(及其相应的值)。 |
boolean |
remove(Object key, Object value) 只有在当前映射到给定值的情况下才删除键的条目。 |
boolean |
replace(K key, V oldValue, V newValue) 仅当当前映射到给定值时才替换密钥的条目。 |
V |
replace(K key, V value) 仅当当前映射到某个值时才替换密钥的条目。 |
void |
replaceAll(BiFunction<? super K, ? super V, ? extends V> function) 用对该条目调用给定函数的结果替换每个条目的值,直到处理完所有条目或者该函数抛出异常。 |
<U> U |
search(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> searchFunction) 对每个(键,值)应用给定的搜索函数返回一个非空结果,如果没有,则返回null。 |
<U> U |
searchEntries(long parallelismThreshold, Function<Entry<K, V>, ? extends U> searchFunction) 在每个条目上应用给定搜索函数返回非空结果,如果没有,则返回null。 |
<U> U |
searchKeys(long parallelismThreshold, Function<? super K, ? extends U> searchFunction) 对每个键应用给定的搜索函数返回非空结果,如果不是,则返回null。 |
<U> U |
searchValues(long parallelismThreshold, Function<? super V, ? extends U> searchFunction) 对每个值应用给定的搜索函数返回一个非空结果,如果没有,则返回null。 |
int |
size() 返回此映射中键 - 值映射的数量。 该实现返回 entrySet().size() 。 |
String |
toString() 返回此映射的字符串表示形式。 |
Collection<V> |
values() 返回此映射中包含的值的 |
Inherited methods |
|
|---|---|
java.util.AbstractMap
|
|
java.lang.Object
|
|
java.util.Map
|
|
java.util.concurrent.ConcurrentMap
|
|
ConcurrentHashMap (int initialCapacity)
创建一个新的空映射,其初始表大小可容纳指定数量的元素,而无需动态调整大小。
| Parameters | |
|---|---|
initialCapacity |
int: The implementation performs internal sizing to accommodate this many elements. |
| Throws | |
|---|---|
IllegalArgumentException |
if the initial capacity of elements is negative |
ConcurrentHashMap (Map<? extends K, ? extends V> m)
使用与给定映射相同的映射创建新映射。
| Parameters | |
|---|---|
m |
Map: the map |
ConcurrentHashMap (int initialCapacity,
float loadFactor)
根据给定的元素数量( initialCapacity )和初始表格密度( loadFactor ),创建具有初始表格大小的新的空白地图。
| Parameters | |
|---|---|
initialCapacity |
int: the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor. |
loadFactor |
float: the load factor (table density) for establishing the initial table size |
| Throws | |
|---|---|
IllegalArgumentException |
if the initial capacity of elements is negative or the load factor is nonpositive |
ConcurrentHashMap (int initialCapacity,
float loadFactor,
int concurrencyLevel)
创建具有基于给定数量的元件(初始表大小的新的空映射 initialCapacity ),表密度( loadFactor ),并同时更新线程(数 concurrencyLevel )。
| Parameters | |
|---|---|
initialCapacity |
int: the initial capacity. The implementation performs internal sizing to accommodate this many elements, given the specified load factor. |
loadFactor |
float: the load factor (table density) for establishing the initial table size |
concurrencyLevel |
int: the estimated number of concurrently updating threads. The implementation may use this value as a sizing hint. |
| Throws | |
|---|---|
IllegalArgumentException |
if the initial capacity is negative or the load factor or concurrencyLevel are nonpositive |
V compute (K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction)
尝试计算指定键和其当前映射值的映射(如果没有当前映射, null )。 整个方法调用是以原子方式执行的。 在进行计算时,其他线程在此映射上的某些尝试更新操作可能会被阻止,因此计算应该简短并且不要尝试更新此映射的任何其他映射。
| Parameters | |
|---|---|
key |
K: key with which the specified value is to be associated |
remappingFunction |
BiFunction: the function to compute a value |
| Returns | |
|---|---|
V |
the new value associated with the specified key, or null if none |
| Throws | |
|---|---|
NullPointerException |
if the specified key or remappingFunction is null |
IllegalStateException |
if the computation detectably attempts a recursive update to this map that would otherwise never complete |
RuntimeException |
or Error if the remappingFunction does so, in which case the mapping is unchanged |
V computeIfAbsent (K key,
Function<? super K, ? extends V> mappingFunction)
如果指定的键尚未与值关联,则尝试使用给定的映射函数计算其值,并将其输入到此映射中,除非null 。 整个方法调用是以原子方式执行的,因此每个键最多应用一次该功能。 在进行计算时,其他线程在此映射上的某些尝试更新操作可能会被阻止,因此计算应该简短并且不要尝试更新此映射的任何其他映射。
| Parameters | |
|---|---|
key |
K: key with which the specified value is to be associated |
mappingFunction |
Function: the function to compute a value |
| Returns | |
|---|---|
V |
the current (existing or computed) value associated with the specified key, or null if the computed value is null |
| Throws | |
|---|---|
NullPointerException |
if the specified key or mappingFunction is null |
IllegalStateException |
if the computation detectably attempts a recursive update to this map that would otherwise never complete |
RuntimeException |
or Error if the mappingFunction does so, in which case the mapping is left unestablished |
V computeIfPresent (K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction)
如果指定键的值存在,则尝试计算给定键和其当前映射值的新映射。 整个方法调用是以原子方式执行的。 在进行计算时,其他线程在此映射上的某些尝试更新操作可能会被阻止,因此计算应该简短并且不要尝试更新此映射的任何其他映射。
| Parameters | |
|---|---|
key |
K: key with which a value may be associated |
remappingFunction |
BiFunction: the function to compute a value |
| Returns | |
|---|---|
V |
the new value associated with the specified key, or null if none |
| Throws | |
|---|---|
NullPointerException |
if the specified key or remappingFunction is null |
IllegalStateException |
if the computation detectably attempts a recursive update to this map that would otherwise never complete |
RuntimeException |
or Error if the remappingFunction does so, in which case the mapping is unchanged |
boolean contains (Object value)
测试某些键是否映射到此表中的指定值。
请注意,此方法在功能上与 containsValue(Object) ,仅用于确保与引入Java集合框架之前支持此方法的类 Hashtable完全兼容。
| Parameters | |
|---|---|
value |
Object: a value to search for |
| Returns | |
|---|---|
boolean |
true if and only if some key maps to the value argument in this table as determined by the equals method; false otherwise |
| Throws | |
|---|---|
NullPointerException |
if the specified value is null |
boolean containsKey (Object key)
测试指定的对象是否是此表中的键。
| Parameters | |
|---|---|
key |
Object: possible key |
| Returns | |
|---|---|
boolean |
true if and only if the specified object is a key in this table, as determined by the equals method; false otherwise |
| Throws | |
|---|---|
NullPointerException |
if the specified key is null |
boolean containsValue (Object value)
如果此映射将一个或多个键映射到指定值,则返回true 。 注意:此方法可能需要全面遍历地图,并且比方法containsKey慢得多。
| Parameters | |
|---|---|
value |
Object: value whose presence in this map is to be tested |
| Returns | |
|---|---|
boolean |
true if this map maps one or more keys to the specified value |
| Throws | |
|---|---|
NullPointerException |
if the specified value is null |
Enumeration<V> elements ()
返回此表中值的枚举。
| Returns | |
|---|---|
Enumeration<V> |
an enumeration of the values in this table |
也可以看看:
Set<Entry<K, V>> entrySet ()
返回此映射中映射的映射的Set视图。 该集合由地图支持,因此对地图的更改反映在集合中,反之亦然。 该组支持元件移除,即从映射中相应的映射,经由Iterator.remove , Set.remove , removeAll , retainAll ,和clear操作。
视图的迭代器和分割器是 weakly consistent 。
视图的 spliterator报告 CONCURRENT , DISTINCT ,并 NONNULL 。
| Returns | |
|---|---|
Set<Entry<K, V>> |
the set view |
boolean equals (Object o)
将指定的对象与此映射进行比较以获得相等性。 如果给定对象是具有与此映射相同映射的映射,则返回true 。 如果在执行此方法期间同时修改其中一个映射,此操作可能会返回误导结果。
| Parameters | |
|---|---|
o |
Object: object to be compared for equality with this map |
| Returns | |
|---|---|
boolean |
true if the specified object is equal to this map |
void forEach (BiConsumer<? super K, ? super V> action)
对此映射中的每个条目执行给定操作,直到处理完所有条目或操作抛出异常为止。 除非实现类另有规定,否则按照条目集迭代的顺序执行操作(如果指定了迭代顺序)。操作抛出的异常会中继给调用者。
| Parameters | |
|---|---|
action |
BiConsumer: The action to be performed for each entry |
void forEach (long parallelismThreshold,
BiConsumer<? super K, ? super V> action)
对每个(键,值)执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
action |
BiConsumer: the action |
void forEach (long parallelismThreshold,
BiFunction<? super K, ? super V, ? extends U> transformer,
Consumer<? super U> action)
对每个(键,值)的每个非空变换执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
BiFunction: a function returning the transformation for an element, or null if there is no transformation (in which case the action is not applied) |
action |
Consumer: the action |
void forEachEntry (long parallelismThreshold,
Function<Entry<K, V>, ? extends U> transformer,
Consumer<? super U> action)
对每个条目的每个非空转换执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case the action is not applied) |
action |
Consumer: the action |
void forEachEntry (long parallelismThreshold,
Consumer<? super Entry<K, V>> action)
为每个条目执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
action |
Consumer: the action |
void forEachKey (long parallelismThreshold,
Function<? super K, ? extends U> transformer,
Consumer<? super U> action)
对每个键的每个非空转换执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case the action is not applied) |
action |
Consumer: the action |
void forEachKey (long parallelismThreshold,
Consumer<? super K> action)
对每个键执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
action |
Consumer: the action |
void forEachValue (long parallelismThreshold,
Function<? super V, ? extends U> transformer,
Consumer<? super U> action)
对每个值的每个非空变换执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case the action is not applied) |
action |
Consumer: the action |
void forEachValue (long parallelismThreshold,
Consumer<? super V> action)
对每个值执行给定的操作。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
action |
Consumer: the action |
V get (Object key)
返回指定键映射到的值 null如果此映射不包含键映射,则返回 null 。
更正式地说,如果该映射包含从键k到值v的映射,例如key.equals(k) ,则该方法返回v ; 否则返回null 。 (最多可以有一个这样的映射。)
| Parameters | |
|---|---|
key |
Object: the key whose associated value is to be returned |
| Returns | |
|---|---|
V |
the value to which the specified key is mapped, or null if this map contains no mapping for the key |
| Throws | |
|---|---|
NullPointerException |
if the specified key is null |
V getOrDefault (Object key, V defaultValue)
返回指定键映射到的值,或者如果此映射不包含键映射,则返回给定的默认值。
| Parameters | |
|---|---|
key |
Object: the key whose associated value is to be returned |
defaultValue |
V: the value to return if this map contains no mapping for the given key |
| Returns | |
|---|---|
V |
the mapping for the key, if present; else the default value |
| Throws | |
|---|---|
NullPointerException |
if the specified key is null |
int hashCode ()
返回此 Map的散列码值,即,对于映射中的每个键值对, key.hashCode() ^ value.hashCode() 。
| Returns | |
|---|---|
int |
the hash code value for this map |
boolean isEmpty ()
如果此映射不包含键 - 值映射,则返回 true 。
该实现返回 size() == 0 。
| Returns | |
|---|---|
boolean |
true if this map contains no key-value mappings |
Set<K> keySet ()
返回此映射中包含的键的Set视图。 该集合由地图支持,因此对地图的更改反映在集合中,反之亦然。 该组支持元件移除,即从该映射中相应的映射,经由Iterator.remove , Set.remove , removeAll , retainAll ,和clear操作。 它不支持add或addAll操作。
该方法返回的集合保证为 ConcurrentHashMap.KeySetView的实例。
视图的迭代器和分割器是 weakly consistent 。
视图的 spliterator报告 CONCURRENT , DISTINCT ,并 NONNULL 。
| Returns | |
|---|---|
Set<K> |
the set view |
KeySetView<K, V> keySet (V mappedValue)
返回此映射中键的Set视图,使用给定的公共映射值进行任何添加(即, add(E)和addAll(Collection) )。 这当然只适用于从该视图中为所有添加使用相同值的情况。
| Parameters | |
|---|---|
mappedValue |
V: the mapped value to use for any additions |
| Returns | |
|---|---|
KeySetView<K, V> |
the set view |
| Throws | |
|---|---|
NullPointerException |
if the mappedValue is null |
Enumeration<K> keys ()
返回此表中键的枚举。
| Returns | |
|---|---|
Enumeration<K> |
an enumeration of the keys in this table |
也可以看看:
long mappingCount ()
返回映射的数量。 应该使用此方法而不是size()因为ConcurrentHashMap可能包含比可以表示为int更多的映射。 返回的值是一个估计值; 如果并发插入或删除,实际计数可能会有所不同。
| Returns | |
|---|---|
long |
the number of mappings |
V merge (K key,
V value,
BiFunction<? super V, ? super V, ? extends V> remappingFunction)
如果指定的键尚未与(非空)值相关联,则将其与给定值相关联。 否则,将该值替换为给定的重映射函数的结果,或者如果null移除。 整个方法调用是以原子方式执行的。 在进行计算时,其他线程在此映射上的某些尝试更新操作可能会被阻止,因此计算应该简短并且不要尝试更新此映射的任何其他映射。
| Parameters | |
|---|---|
key |
K: key with which the specified value is to be associated |
value |
V: the value to use if absent |
remappingFunction |
BiFunction: the function to recompute a value if present |
| Returns | |
|---|---|
V |
the new value associated with the specified key, or null if none |
| Throws | |
|---|---|
NullPointerException |
if the specified key or the remappingFunction is null |
RuntimeException |
or Error if the remappingFunction does so, in which case the mapping is unchanged |
KeySetView<K, Boolean> newKeySet ()
创建一个新的 Set ,由给定类型的ConcurrentHashMap支持 Boolean.TRUE 。
| Returns | |
|---|---|
KeySetView<K, Boolean> |
the new set |
KeySetView<K, Boolean> newKeySet (int initialCapacity)
创建一个由给定类型的ConcurrentHashMap支持的新的 Set到 Boolean.TRUE 。
| Parameters | |
|---|---|
initialCapacity |
int: The implementation performs internal sizing to accommodate this many elements. |
| Returns | |
|---|---|
KeySetView<K, Boolean> |
the new set |
| Throws | |
|---|---|
IllegalArgumentException |
if the initial capacity of elements is negative |
V put (K key,
V value)
将指定的键映射到此表中的指定值。 密钥和值都不能为空。
通过使用与原始密钥相同的密钥调用 get方法可以检索该值。
| Parameters | |
|---|---|
key |
K: key with which the specified value is to be associated |
value |
V: value to be associated with the specified key |
| Returns | |
|---|---|
V |
the previous value associated with key, or null if there was no mapping for key |
| Throws | |
|---|---|
NullPointerException |
if the specified key or value is null |
void putAll (Map<? extends K, ? extends V> m)
将指定映射中的所有映射复制到此映射。 这些映射会替换此映射对当前指定映射中的任何键的所有映射。
| Parameters | |
|---|---|
m |
Map: mappings to be stored in this map |
V putIfAbsent (K key,
V value)
如果指定的键尚未与值相关联,则将其与给定值相关联。 这相当于这个map :
if (!map.containsKey(key))
return map.put(key, value);
else
return map.get(key); except that the action is performed atomically.
| Parameters | |
|---|---|
key |
K: key with which the specified value is to be associated |
value |
V: value to be associated with the specified key |
| Returns | |
|---|---|
V |
the previous value associated with the specified key, or null if there was no mapping for the key |
| Throws | |
|---|---|
NullPointerException |
if the specified key or value is null |
U reduce (long parallelismThreshold,
BiFunction<? super K, ? super V, ? extends U> transformer,
BiFunction<? super U, ? super U, ? extends U> reducer)
返回使用给定的缩减器合并值累积所有(键,值)对的给定变换的结果,如果不是,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
BiFunction: a function returning the transformation for an element, or null if there is no transformation (in which case it is not combined) |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
U |
the result of accumulating the given transformation of all (key, value) pairs |
Entry<K, V> reduceEntries (long parallelismThreshold, BiFunction<Entry<K, V>, Entry<K, V>, ? extends Entry<K, V>> reducer)
返回使用给定reducer合并值的所有条目的累积结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
Entry<K, V> |
the result of accumulating all entries |
U reduceEntries (long parallelismThreshold,
Function<Entry<K, V>, ? extends U> transformer,
BiFunction<? super U, ? super U, ? extends U> reducer)
返回使用给定缩减器合并值累积给定转换的结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case it is not combined) |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
U |
the result of accumulating the given transformation of all entries |
double reduceEntriesToDouble (long parallelismThreshold,
ToDoubleFunction<Entry<K, V>> transformer,
double basis,
DoubleBinaryOperator reducer)
返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToDoubleFunction: a function returning the transformation for an element |
basis |
double: the identity (initial default value) for the reduction |
reducer |
DoubleBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
double |
the result of accumulating the given transformation of all entries |
int reduceEntriesToInt (long parallelismThreshold,
ToIntFunction<Entry<K, V>> transformer,
int basis,
IntBinaryOperator reducer)
返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToIntFunction: a function returning the transformation for an element |
basis |
int: the identity (initial default value) for the reduction |
reducer |
IntBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
int |
the result of accumulating the given transformation of all entries |
long reduceEntriesToLong (long parallelismThreshold,
ToLongFunction<Entry<K, V>> transformer,
long basis,
LongBinaryOperator reducer)
返回使用给定缩减器合并值并将给定基础作为标识值累加给定变换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToLongFunction: a function returning the transformation for an element |
basis |
long: the identity (initial default value) for the reduction |
reducer |
LongBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
long |
the result of accumulating the given transformation of all entries |
K reduceKeys (long parallelismThreshold,
BiFunction<? super K, ? super K, ? extends K> reducer)
返回使用给定缩减器合并值累积所有键的结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
K |
the result of accumulating all keys using the given reducer to combine values, or null if none |
U reduceKeys (long parallelismThreshold,
Function<? super K, ? extends U> transformer,
BiFunction<? super U, ? super U, ? extends U> reducer)
返回使用给定的缩减器合并值累加给定所有键的转换的结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case it is not combined) |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
U |
the result of accumulating the given transformation of all keys |
double reduceKeysToDouble (long parallelismThreshold,
ToDoubleFunction<? super K> transformer,
double basis,
DoubleBinaryOperator reducer)
返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToDoubleFunction: a function returning the transformation for an element |
basis |
double: the identity (initial default value) for the reduction |
reducer |
DoubleBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
double |
the result of accumulating the given transformation of all keys |
int reduceKeysToInt (long parallelismThreshold,
ToIntFunction<? super K> transformer,
int basis,
IntBinaryOperator reducer)
返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToIntFunction: a function returning the transformation for an element |
basis |
int: the identity (initial default value) for the reduction |
reducer |
IntBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
int |
the result of accumulating the given transformation of all keys |
long reduceKeysToLong (long parallelismThreshold,
ToLongFunction<? super K> transformer,
long basis,
LongBinaryOperator reducer)
返回使用给定缩减器累加给定所有键的转换以合并值,并将给定基准作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToLongFunction: a function returning the transformation for an element |
basis |
long: the identity (initial default value) for the reduction |
reducer |
LongBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
long |
the result of accumulating the given transformation of all keys |
double reduceToDouble (long parallelismThreshold,
ToDoubleBiFunction<? super K, ? super V> transformer,
double basis,
DoubleBinaryOperator reducer)
返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToDoubleBiFunction: a function returning the transformation for an element |
basis |
double: the identity (initial default value) for the reduction |
reducer |
DoubleBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
double |
the result of accumulating the given transformation of all (key, value) pairs |
int reduceToInt (long parallelismThreshold,
ToIntBiFunction<? super K, ? super V> transformer,
int basis,
IntBinaryOperator reducer)
返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToIntBiFunction: a function returning the transformation for an element |
basis |
int: the identity (initial default value) for the reduction |
reducer |
IntBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
int |
the result of accumulating the given transformation of all (key, value) pairs |
long reduceToLong (long parallelismThreshold,
ToLongBiFunction<? super K, ? super V> transformer,
long basis,
LongBinaryOperator reducer)
返回使用给定的缩减器将所有(键,值)对的给定变换累加以合并值,并将给定基础作为标识值的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToLongBiFunction: a function returning the transformation for an element |
basis |
long: the identity (initial default value) for the reduction |
reducer |
LongBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
long |
the result of accumulating the given transformation of all (key, value) pairs |
V reduceValues (long parallelismThreshold,
BiFunction<? super V, ? super V, ? extends V> reducer)
返回使用给定缩减器合并值累加所有值的结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
V |
the result of accumulating all values |
U reduceValues (long parallelismThreshold,
Function<? super V, ? extends U> transformer,
BiFunction<? super U, ? super U, ? extends U> reducer)
返回使用给定的缩减器合并值累积所有值的给定变换的结果,如果没有,则返回null。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
Function: a function returning the transformation for an element, or null if there is no transformation (in which case it is not combined) |
reducer |
BiFunction: a commutative associative combining function |
| Returns | |
|---|---|
U |
the result of accumulating the given transformation of all values |
double reduceValuesToDouble (long parallelismThreshold,
ToDoubleFunction<? super V> transformer,
double basis,
DoubleBinaryOperator reducer)
返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToDoubleFunction: a function returning the transformation for an element |
basis |
double: the identity (initial default value) for the reduction |
reducer |
DoubleBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
double |
the result of accumulating the given transformation of all values |
int reduceValuesToInt (long parallelismThreshold,
ToIntFunction<? super V> transformer,
int basis,
IntBinaryOperator reducer)
返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToIntFunction: a function returning the transformation for an element |
basis |
int: the identity (initial default value) for the reduction |
reducer |
IntBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
int |
the result of accumulating the given transformation of all values |
long reduceValuesToLong (long parallelismThreshold,
ToLongFunction<? super V> transformer,
long basis,
LongBinaryOperator reducer)
返回使用给定的缩减器合并值并将给定基础作为标识值累加给定所有值的转换的结果。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
transformer |
ToLongFunction: a function returning the transformation for an element |
basis |
long: the identity (initial default value) for the reduction |
reducer |
LongBinaryOperator: a commutative associative combining function |
| Returns | |
|---|---|
long |
the result of accumulating the given transformation of all values |
V remove (Object key)
从此映射中删除键(及其相应的值)。 如果该键不在地图中,该方法不执行任何操作。
| Parameters | |
|---|---|
key |
Object: the key that needs to be removed |
| Returns | |
|---|---|
V |
the previous value associated with key, or null if there was no mapping for key |
| Throws | |
|---|---|
NullPointerException |
if the specified key is null |
boolean remove (Object key, Object value)
只有在当前映射到给定值的情况下才删除键的条目。 这相当于这个map :
if (map.containsKey(key)
&& Objects.equals(map.get(key), value)) {
map.remove(key);
return true;
} else {
return false;
} except that the action is performed atomically.
| Parameters | |
|---|---|
key |
Object: key with which the specified value is associated |
value |
Object: value expected to be associated with the specified key |
| Returns | |
|---|---|
boolean |
true if the value was removed |
| Throws | |
|---|---|
NullPointerException |
if the specified key is null |
boolean replace (K key,
V oldValue,
V newValue)
仅当当前映射到给定值时才替换密钥的条目。 这相当于这个map :
if (map.containsKey(key)
&& Objects.equals(map.get(key), oldValue)) {
map.put(key, newValue);
return true;
} else {
return false;
} except that the action is performed atomically.
| Parameters | |
|---|---|
key |
K: key with which the specified value is associated |
oldValue |
V: value expected to be associated with the specified key |
newValue |
V: value to be associated with the specified key |
| Returns | |
|---|---|
boolean |
true if the value was replaced |
| Throws | |
|---|---|
NullPointerException |
if any of the arguments are null |
V replace (K key,
V value)
仅当当前映射到某个值时才替换密钥的条目。 这相当于这个map :
if (map.containsKey(key))
return map.put(key, value);
else
return null; except that the action is performed atomically.
| Parameters | |
|---|---|
key |
K: key with which the specified value is associated |
value |
V: value to be associated with the specified key |
| Returns | |
|---|---|
V |
the previous value associated with the specified key, or null if there was no mapping for the key |
| Throws | |
|---|---|
NullPointerException |
if the specified key or value is null |
void replaceAll (BiFunction<? super K, ? super V, ? extends V> function)
用对该条目调用给定函数的结果替换每个条目的值,直到处理完所有条目或者该函数抛出异常。 函数抛出的异常会传递给调用者。
| Parameters | |
|---|---|
function |
BiFunction: the function to apply to each entry |
U search (long parallelismThreshold,
BiFunction<? super K, ? super V, ? extends U> searchFunction)
对每个(键,值)应用给定的搜索函数返回一个非空结果,如果没有,则返回null。 成功后,进一步的元素处理被抑制,任何其他并行调用搜索函数的结果都将被忽略。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
searchFunction |
BiFunction: a function returning a non-null result on success, else null |
| Returns | |
|---|---|
U |
a non-null result from applying the given search function on each (key, value), or null if none |
U searchEntries (long parallelismThreshold,
Function<Entry<K, V>, ? extends U> searchFunction)
在每个条目上应用给定搜索函数返回非空结果,如果没有,则返回null。 成功后,进一步的元素处理被抑制,任何其他并行调用搜索函数的结果都将被忽略。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
searchFunction |
Function: a function returning a non-null result on success, else null |
| Returns | |
|---|---|
U |
a non-null result from applying the given search function on each entry, or null if none |
U searchKeys (long parallelismThreshold,
Function<? super K, ? extends U> searchFunction)
对每个键应用给定的搜索函数返回非空结果,如果不是,则返回null。 成功后,进一步的元素处理被抑制,任何其他并行调用搜索函数的结果都将被忽略。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
searchFunction |
Function: a function returning a non-null result on success, else null |
| Returns | |
|---|---|
U |
a non-null result from applying the given search function on each key, or null if none |
U searchValues (long parallelismThreshold,
Function<? super V, ? extends U> searchFunction)
对每个值应用给定的搜索函数返回一个非空结果,如果没有,则返回null。 成功后,进一步的元素处理被抑制,任何其他并行调用搜索函数的结果都将被忽略。
| Parameters | |
|---|---|
parallelismThreshold |
long: the (estimated) number of elements needed for this operation to be executed in parallel |
searchFunction |
Function: a function returning a non-null result on success, else null |
| Returns | |
|---|---|
U |
a non-null result from applying the given search function on each value, or null if none |
int size ()
返回此映射中键 - 值映射的数量。 如果地图包含多个Integer.MAX_VALUE元素,则返回Integer.MAX_VALUE 。
该实现返回 entrySet().size() 。
| Returns | |
|---|---|
int |
the number of key-value mappings in this map |
String toString ()
返回此映射的字符串表示形式。 字符串表示由大括号(“ {} ”)中包含的键值映射列表(无特定顺序)组成。 相邻映射由字符", " (逗号和空格)分隔。 每个键值映射都呈现为键后跟一个等号(“ = ”),后跟相关联的值。
| Returns | |
|---|---|
String |
a string representation of this map |
Collection<V> values ()
返回此映射中包含的值的Collection视图。 该集合由地图支持,因此地图的更改会反映在集合中,反之亦然。 该collection支持元素移除,即从该映射中相应的映射,经由Iterator.remove , Collection.remove , removeAll , retainAll ,和clear操作。 它不支持add或addAll操作。
视图的迭代器和分割器是 weakly consistent 。
该视图的 spliterator报告 CONCURRENT和 NONNULL 。
| Returns | |
|---|---|
Collection<V> |
the collection view |