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