Java IdentityHashMap isEmpty()方法与示例
IdentityHashMap类isEmpty()方法
isEmpty()方法在java.util包中可用。
isEmpty()方法用于检查此IdentityHashMap是“空”还是“非空”。
isEmpty()方法是一个非静态方法,只能使用类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
在检查此IdentityHashMap的空白状态时,isEmpty()方法不会引发异常。
语法:
public boolean isEmpty();
参数:
它不接受任何参数。
返回值:
该方法的返回类型为布尔值,当此IdentityHashMap为“空”或“非空”时,它返回true。
示例
//Java程序演示示例
//isEmpty()IdentityHashMap的布尔方法的说明
import java.util.*;
public class IsEmptyOfIdentityHashMap {
public static void main(String[] args) {
//实例化一个IdentityHashMap对象
Map < Integer, String > map = new IdentityHashMap < Integer, String > ();
//通过使用put()方法是添加
//IdentityHashMap中的键值对
map.put(10, "C");
map.put(20, "C++");
map.put(50, "JAVA");
map.put(40, "PHP");
map.put(30, "SFDC");
//显示IdentityHashMap-
System.out.println("IdentityHashMap: " + map);
//通过使用isEmpty()方法是
//检查此IdentityHashMap是否为
//空与否
boolean status = map.isEmpty();
//显示状态
System.out.print("map.isEmpty(): ");
System.out.println(status);
}
}输出结果
IdentityHashMap: {20=C++, 40=PHP, 50=JAVA, 30=SFDC, 10=C}
map.isEmpty(): false