java.util.hashset_java.util.HashSet.clone()

描述

该clone()方法用于返回此HashSet实例的浅表副本。

声明

以下是java.util.HashSet.clone()方法的声明。

public Object clone()

参数

NA

返回值

方法调用返回此set的浅表副本。

异常

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 newset = new HashSet ();

HashSet cloneset = new HashSet ();

// 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]

描述 该clone()方法用于返回此HashSet实例的浅表副本。 声明 以下是java.util.HashSet.clone()方法的声明。 public Object clone() 参数 NA 返回值 方法调用返回此set的浅表副本。 异常 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 newset = new HashSet (); HashSet cloneset = new HashSet (); // 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]
经验分享 程序员 微信小程序 职场和发展