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()
相關用法
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet size()用法及代碼示例
- Java ConcurrentSkipListSet iterator()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet remove()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java ConcurrentSkipListSet clear()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet clone() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。