java.util.concurrent.ConcurrentHashMap的isEmpty()方法是Java中的內置函數,該函數檢查此映射是否包含任何鍵-值映射並返回布爾值。
用法:
public boolean isEmpty()
返回值:該函數返回一個布爾值。如果ConcurrentHashMap為空,則返回true,否則返回false。
以下示例程序旨在說明isEmpty()方法的使用:
示例1:在此程序中,ConcurrentHashMap是非空的。
// Java Program Demonstrate isEmpty()
// method of ConcurrentHashMap */
import java.util.concurrent.*;
class ConcurrentHashMapDemo {
public static void main(String[] args)
{
ConcurrentHashMap<Integer, String>
chm = new ConcurrentHashMap<Integer, String>();
chm.put(100, "Geeks");
chm.put(101, "for");
chm.put(102, "Geeks");
// Checking for the emptiness of Map
if (chm.isEmpty()) {
System.out.println("The ConcurrentHashMap"
+ " is empty.");
}
else {
// Displaying the ConcurrentHashMap
System.out.println("The Mappings are: "
+ chm);
}
}
}
輸出:
The Mappings are: {100=Geeks, 101=for, 102=Geeks}
示例2:在此程序中,ConcurrentHashMap是非空的。
// Java Program Demonstrate isEmpty()
// method of ConcurrentHashMap */
import java.util.concurrent.*;
class GFG {
public static void main(String[] args)
{
ConcurrentHashMap chm = new ConcurrentHashMap();
// Checking for the emptiness of Map
if (chm.isEmpty()) {
System.out.println("The ConcurrentHashMap"
+ " is empty.");
}
else {
// Displaying the ConcurrentHashMap
System.out.println("The Mappings are: "
+ chm);
}
}
}
輸出:
The ConcurrentHashMap is empty.
參考: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html#isEmpty()
相關用法
- Java ConcurrentHashMap put()用法及代碼示例
- Java ConcurrentHashMap get()用法及代碼示例
- Java ConcurrentHashMap size()用法及代碼示例
- Java ConcurrentHashMap remove()用法及代碼示例
- Java ConcurrentHashMap contains()用法及代碼示例
- Java ConcurrentHashMap putAll()用法及代碼示例
- Java ConcurrentHashMap putIfAbsent()用法及代碼示例
- Java ConcurrentHashMap containsKey()用法及代碼示例
- Java ConcurrentHashMap containsValue()用法及代碼示例
- Java ConcurrentHashMap elements()用法及代碼示例
- Java ConcurrentHashMap values()用法及代碼示例
- Java ConcurrentHashMap compute()用法及代碼示例
- Java ConcurrentHashMap entrySet()用法及代碼示例
- Java ConcurrentHashMap computeIfAbsent()用法及代碼示例
- Java ConcurrentHashMap keySet()用法及代碼示例
注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 ConcurrentHashMap isEmpty() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。