El método spliterator() de LinkedBlockingDeque devuelve un Spliterator en los elementos de LinkedBlockingDeque. El iterador devuelto es débilmente coherente. Spliterator se puede usar con Streams en Java 8. Spliterator puede atravesar elementos individualmente y también en masa.
Sintaxis:
public Spliterator spliterator()
Devoluciones: este método devuelve un Spliterator sobre los elementos en LinkedBlockingDeque.
Los siguientes programas ilustran el método spliterator() de LinkedBlockingDeque:
Programa 1:
// Java Program to demonstrate spliterator() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add elements LBD.add(22); LBD.add(34); LBD.add(45); LBD.add(67); // create Spliterator of Deque // using spliterator() method Spliterator<Integer> numbers = LBD.spliterator(); // getExactSize of Spliterator System.out.println("Size of Spliterator : " + numbers.estimateSize()); System.out.println("list of Numbers:"); // forEachRemaining method of Spliterator numbers.forEachRemaining((n) -> System.out.println(n)); } }
Producción:
Size of Spliterator : 4 list of Numbers: 22 34 45 67
Programa 2:
// Java Program to demonstrate spliterator() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD = new LinkedBlockingDeque<String>(); // Add numbers to front of LinkedBlockingDeque LBD.add("Geeks"); LBD.add("forGeeks"); LBD.add("A"); LBD.add("Computer"); LBD.add("Portal"); // create Spliterator of Deque // using spliterator() method Spliterator<String> numbers = LBD.spliterator(); // getExactSize of Spliterator System.out.println("Size of Spliterator : " + numbers.estimateSize()); System.out.println("list of Strings:"); // forEachRemaining method of Spliterator numbers.forEachRemaining((n) -> System.out.println(n)); } }
Producción:
Size of Spliterator : 5 list of Strings: Geeks forGeeks A Computer Portal
Referencia: <https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#spliterator–