void clear()
描述 (Description)
clear()方法用于从此映射中删除所有映射。
声明 (Declaration)
以下是java.util.IdentityHashMap.clear()方法的声明。
public void clear()
参数 (Parameters)
NA
返回值 (Return Value)
NA
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.IdentityHashMap.clear()的用法
package com.iowiki;
import java.util.*;
public class IdentityHashMapDemo {
public static void main(String args[]) {
// create identity hash map
IdentityHashMap ihmap = new IdentityHashMap();
// populate the map
ihmap.put(1, "java");
ihmap.put(2, "util");
ihmap.put(3, "package");
System.out.println("Initial Map content: " + ihmap);
// clear the map
ihmap.clear();
System.out.println("Map content after clear: " + ihmap);
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Initial Map content: {1=java, 3=package, 2=util}
Map content after clear: {}