Java.util.Dictionary.isEmpty() 方法
描述
java.util.Dictionary.isEmpty() 方法检查此字典是否没有键值。
声明
以下是 java.util.Dictionary.isEmpty() 方法的声明
public abstract boolean isEmpty()
参数
NA
返回值
如果该字典没有值的键,则此方法返回 true; 否则为 false 。
异常
NA
示例
下面的例子展示了 java.util.Dictionary.isEmpty() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class DictionaryDemo {
public static void main(String[] args) {
// create a new hashtable
Dictionary d = new Hashtable();
// add elements in the hashtable
d.put("1", "Chocolate");
d.put("2", "Cocoa");
d.put("5", "Coffee");
// return true if this dictionary maps no keys to value.
boolean b = d.isEmpty();
System.out.println("Dictionary is empty:" + b);
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Dictionary is empty:false

