Saturday, May 16, 2026
HomeLanguagesJavaConcurrentSkipListMap clone() method in Java with Examples

ConcurrentSkipListMap clone() method in Java with Examples

The clone() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which returns a shallow copy of this ConcurrentSkipListMap instance. The keys and values themselves are not cloned.

Syntax:

ConcurrentSkipListMap.clone()

Parameter: The function does not accept any parameter.

Parameter: This method do not accepts any parameter.

Return Value: The function returns a shallow copy of this ConcurrentSkipListMap.

Below programs illustrate the above method:

Program 1:




// Java Program Demonstrate clone()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.ConcurrentSkipListMap;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        // using ConcurrentSkipListMap()
        ConcurrentSkipListMap<Integer, Integer> mpp
            = new ConcurrentSkipListMap<Integer,
                                        Integer>();
  
        // Adding elements to this map
        mpp.put(1, 1);
        mpp.put(5, 2);
        mpp.put(2, 7);
  
        // Printing the ConcurrentSkipListMap
        System.out.println("Map: " + mpp);
  
        // Cloning the ConcurrentSkipListMap
        ConcurrentSkipListMap<Integer, Integer>
            clone_mpp = mpp.clone();
  
        // Adding elements to the clone map
        clone_mpp.put(7, 9);
  
        System.out.println("Cloned map is:  "
                           + clone_mpp);
    }
}


Output:

Map: {1=1, 2=7, 5=2}
Cloned map is:  {1=1, 2=7, 5=2, 7=9}

Program 2:




// Java Program Demonstrate clone()
// method of ConcurrentSkipListMap
  
import java.util.concurrent.ConcurrentSkipListMap;
  
class GFG {
    public static void main(String[] args)
    {
  
        // Initializing the map
        // using ConcurrentSkipListMap()
        ConcurrentSkipListMap<Integer, Integer>
            mpp = new ConcurrentSkipListMap<Integer,
                                            Integer>();
  
        // Adding elements to this map
        mpp.put(10, 5);
        mpp.put(54, 20);
        mpp.put(2, 7);
  
        // Printing the ConcurrentSkipListMap
        System.out.println("Map: " + mpp);
  
        // Cloning the ConcurrentSkipListMap
        ConcurrentSkipListMap<Integer, Integer>
            clone_mpp = mpp.clone();
  
        // Adding elements to the clone map
        clone_mpp.put(17, 9);
  
        System.out.println("Cloned map is:  "
                           + clone_mpp);
    }
}


Output:

Map: {2=7, 10=5, 54=20}
Cloned map is:  {2=7, 10=5, 17=9, 54=20}

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#clone–

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS