El método clone() de java.util.concurrent.ConcurrentSkipListMap es una función integrada en Java que devuelve una copia superficial de esta instancia de ConcurrentSkipListMap. Las claves y los valores en sí no se clonan.
Sintaxis:
ConcurrentSkipListMap.clone()
Parámetro: La función no acepta ningún parámetro.
Parámetro: Este método no acepta ningún parámetro.
Valor devuelto: la función devuelve una copia superficial de este ConcurrentSkipListMap.
Los siguientes programas ilustran el método anterior:
Programa 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); } }
Map: {1=1, 2=7, 5=2} Cloned map is: {1=1, 2=7, 5=2, 7=9}
Programa 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); } }
Map: {2=7, 10=5, 54=20} Cloned map is: {2=7, 10=5, 17=9, 54=20}
Referencia: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/ConcurrentSkipListMap.html#clone–
Publicación traducida automáticamente
Artículo escrito por Twinkl Bajaj y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA