ConcurrentSkipListSet 中的 clone() 方法在 Java 中

ConcurrentSkipListSet 中的 clone() 方法在 Java 中

java.util.concurrent.ConcurrentSkipListSet 的 clone() 方法是 Java 中的内置函数,它返回此 ConcurrentSkipListSet 实例的浅表副本。

语法:

ConcurrentSkipListSet.clone()

参数: 此函数不接受任何参数。

返回值: 该函数返回 ConcurrentSkipListSet 的浅表副本。

下面的程序说明了 ConcurrentSkipListSet.clone() 方法:

程序1:

// Java Program Demonstrate clone()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
  
class ConcurrentSkipListSetCloneExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet<Integer>
            set = new ConcurrentSkipListSet<Integer>();
  
        // Adding elements to this set
        for (int i = 10; i <= 15; i++)
            set.add(i);
  
        // Printing elements of the set
        System.out.println("The set contains: " + set);
  
        // Cloning the ConcurrentSkipListSet
        ConcurrentSkipListSet<Integer> clone_set = set.clone();
  
        // Adding elements to the clone set
        clone_set.add(16);
  
        // Printing elements of the clone set
        System.out.println("The clone set contains: " + clone_set);
    }
}
The set contains: [10, 11, 12, 13, 14, 15]
The clone set contains: [10, 11, 12, 13, 14, 15, 16]

程序2:

// Java Program Demonstrate clone()
// method of ConcurrentSkipListSet */
import java.util.concurrent.*;
  
class ConcurrentSkipListSetCloneExample2 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet<String>
            set = new ConcurrentSkipListSet<String>();
  
        // Adding elements to this set
        set.add("Gfg");
        set.add("is");
        set.add("fun");
  
        // Printing elements of the set
        System.out.println("The set contains: " + set);
  
        // Cloning the ConcurrentSkipListSet
        ConcurrentSkipListSet<String> clone_set = set.clone();
  
        // Adding elements to the clone set
        clone_set.add("site");
  
        // Printing elements of the clone set
        System.out.println("The clone set contains: " + clone_set);
    }
}
The set contains: [Gfg, fun, is]
The clone set contains: [Gfg, fun, is, site]

引用 : https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#clone()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程