java.util.HashSet.clone() 方法
描述
clone() 方法用于返回此 HashSet 实例的浅表副本。
声明
以下是 java.util.HashSet.clone() 方法的声明。
public Object clone()
参数
NA
返回值
方法调用返回此集合的浅表副本。
异常
NA
示例
下面的例子展示了 java.util.HashSet.clone() 的用法。
package com.tutorialspoint;
import java.util.*;
public class HashSetDemo {
public static void main(String args[]) {
// create two hash sets
HashSet <String> newset = new HashSet <String>();
HashSet <String> cloneset = new HashSet <String>();
// populate hash set
newset.add("Learning");
newset.add("Easy");
newset.add("Simply");
// clone the hash set
cloneset = (HashSet)newset.clone();
System.out.println("Hash set values: "+ newset);
System.out.println("Clone Hash set values: "+ cloneset);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Hash set values: [Learning, Simply, Easy] Clone Hash set values: [Learning, Simply, Easy]

