El método java.util.concurrent.ConcurrentSkipListSet.clear() es una función integrada en Java que elimina todos los elementos de este conjunto.
Sintaxis:
ConcurrentSkipListSet.clear()
Parámetros: La función no acepta ningún parámetro.
Valor devuelto: la función no devuelve nada.
Los siguientes programas ilustran el método ConcurrentSkipListSet.clear():
Programa 1:
/* Java Program Demonstrate clear() method of ConcurrentSkipListSet() */ import java.util.concurrent.*; class ConcurrentSkipListSetClearExample1 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for (int i = 10; i <= 50; i += 10) Lset.add(i); // Printing elements of the set System.out.println("The set contains: " + Lset); // Clear the set Lset.clear(); // Printing elements of the set after clear operation System.out.println("After clear operation the set contains: " + Lset); } }
Producción:
The set contains: [10, 20, 30, 40, 50] After clear operation the set contains: []
Programa 2:
/* Java Program Demonstrate clear() method of ConcurrentSkipListSet() */ import java.util.concurrent.*; class ConcurrentSkipListSetClearExample2 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<String> Lset = new ConcurrentSkipListSet<String>(); // Adding elements to this set Lset.add("alex"); Lset.add("bob"); Lset.add("chuck"); Lset.add("drake"); Lset.add("eric"); // Printing elements of the set System.out.println("The set contains: " + Lset); // Clear the set Lset.clear(); // Printing elements of the set after clear operation System.out.println("After clear operation the set contains: " + Lset); } }
Producción:
The set contains: [alex, bob, chuck, drake, eric] After clear operation the set contains: []
Referencia: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#clear–
Publicación traducida automáticamente
Artículo escrito por rupesh_rao y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA