ConcurrentHashMap 類的 newKeySet() 方法創建一個由 ConcurrentHashMap 從給定類型到 Boolean.TRUE 支持的新集合。
用法
public static <K> ConcurrentHashMap.KeySetView<K,Boolean> newKeySet()
public static <K> ConcurrentHashMap.KeySetView<K,Boolean> newKeySet(int initialCapacity)
參數
沒有傳遞參數。
返回
新套裝
拋出
不會拋出任何異常。
例子1
import java.util.Set;
import java.util.concurrent.*;
class ConcurrentHashMapnewKeySetExample1 {
public static void main(String[] args)
{
Set<String> hashmap = ConcurrentHashMap.newKeySet();
hashmap.add("AA");
hashmap.add("BBB");
hashmap.add("CCC");
hashmap.add("DDD");
System.out.println(" Mappings:"+ hashmap);
}
}
輸出:
Mappings:[AA, CCC, BBB, DDD]
例子2
import java.util.Set;
import java.util.concurrent.*;
class ConcurrentHashMapnewKeySetExample2 {
public static void main(String[] args)
{
Set<String> hashmap = ConcurrentHashMap.newKeySet(6);
hashmap.add("AA");
hashmap.add("BBB");
hashmap.add("CCC");
hashmap.add("DDD");
System.out.println(" Mappings:"+ hashmap);
System.out.println(" Mapping size:"+ hashmap.size());
}
}
輸出:
Mappings:[AA, CCC, BBB, DDD] Mapping size:4
相關用法
- Java ConcurrentHashMap contains()用法及代碼示例
- Java ConcurrentHashMap elements()用法及代碼示例
- Java ConcurrentHashMap forEach()用法及代碼示例
- Java ConcurrentHashMap putIfAbsent()用法及代碼示例
- Java ConcurrentHashMap computeIfAbsent()用法及代碼示例
- Java ConcurrentHashMap isEmpty()用法及代碼示例
- Java ConcurrentHashMap equals()用法及代碼示例
- Java ConcurrentHashMap putAll()用法及代碼示例
- Java ConcurrentHashMap mappingCount()用法及代碼示例
- Java ConcurrentHashMap merge()用法及代碼示例
- Java ConcurrentHashMap hashcode()用法及代碼示例
- Java ConcurrentHashMap containsKey()用法及代碼示例
- Java ConcurrentHashMap put()用法及代碼示例
- Java ConcurrentHashMap computeIfPresent()用法及代碼示例
- Java ConcurrentHashMap toString()用法及代碼示例
- Java ConcurrentHashMap replace()用法及代碼示例
- Java ConcurrentHashMap clear()用法及代碼示例
- Java ConcurrentHashMap size()用法及代碼示例
- Java ConcurrentHashMap remove()用法及代碼示例
- Java ConcurrentHashMap keys()用法及代碼示例
注:本文由純淨天空篩選整理自 Java ConcurrentHashMap newKeySet() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。