ConcurrentSkipListSet clone() method in Java
The clone() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns a shallow copy of this ConcurrentSkipListSet instance.
Syntax:
ConcurrentSkipListSet.clone()
Parameters: The function does not accept any parameter.
Return Value: The function returns a shallow copy of ConcurrentSkipListSet.
Below programs illustrate the ConcurrentSkipListSet.clone() method:
Program 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]
Program 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]
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#clone()
Recommended Posts:
- ConcurrentSkipListSet first() method in Java
- ConcurrentSkipListSet contains() method in Java
- ConcurrentSkipListSet add() method in Java
- ConcurrentSkipListSet last() method in Java
- ConcurrentSkipListSet size() method in Java
- ConcurrentSkipListSet spliterator() method in Java
- ConcurrentSkipListSet remove() method in Java
- ConcurrentSkipListSet higher() method in Java
- ConcurrentSkipListSet ceiling() method in Java
- ConcurrentSkipListSet headSet() method in Java
- ConcurrentSkipListSet floor() method in Java
- ConcurrentSkipListSet pollFirst() method in Java
- ConcurrentSkipListSet isEmpty() method in Java
- ConcurrentSkipListSet iterator() method in Java
- ConcurrentSkipListSet equals() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

