ArrayDeque spliterator() method in Java Last Updated : 10 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The spliterator() method of ArrayDeque returns a Spliterator of the same elements as ArrayDeque but created Spliterator is late-binding and fail-fast. A late-binding Spliterator binds to the source of elements means ArrayDeque at the point of first traversal, first split, or first query for estimated size, rather than at the time the Spliterator is created. It can be used with Streams in Java 8. Also it can traverse elements individually and in bulk too. Spliterator is better way to traverse over element because it provides more control on elements. Syntax: public Spliterator<E> spliterator() Returns: This method returns a Spliterator over the elements in ArrayDeque. Below programs illustrate spliterator() method of ArrayDeque: Example 1: To demonstrate spliterator() method on ArrayDeque which contains a list of Numbers. Java // Java Program Demonstrate spliterator() // method of ArrayDeque import java.util.*; public class GFG { public static void main(String[] args) { // create an ArrayDeque which going to // contains a list of numbers ArrayDeque<Integer> list = new ArrayDeque<Integer>(); // Add numbers to list list.add(1234); list.add(2345); list.add(3456); list.add(4567); // create Spliterator of ArrayDeque // using spliterator() method Spliterator<Integer> numbers = list.spliterator(); // print result from Spliterator System.out.println("list of Numbers:"); // forEachRemaining method of Spliterator numbers.forEachRemaining((n) -> System.out.println(n)); } } Output: list of Numbers: 1234 2345 3456 4567 Example 2: To demonstrate spliterator() method on ArrayDeque which contains list of Strings. Java // Java Program Demonstrate spliterator() // method of ArrayDeque import java.util.*; public class GFG { public static void main(String[] args) { // create an ArrayDeque which going to // contains a list of Strings ArrayDeque<String> list = new ArrayDeque<String>(); // Add Strings to list // each string represents city name list.add("Kolkata"); list.add("Delhi"); list.add("Mumbai"); list.add("Jaipur"); // create Spliterator of ArrayDeque // using spliterator() method Spliterator<String> cities = list.spliterator(); // print result from Spliterator System.out.println("list of Cities:"); // forEachRemaining method of Spliterator cities.forEachRemaining( (n) -> System.out.println("City Name: " + n)); } } Output: list of Cities: City Name: Kolkata City Name: Delhi City Name: Mumbai City Name: Jaipur Reference: https://docs.oracle.com/javase/10/docs/api/java/util/ArrayDeque.html#spliterator() Comment More infoAdvertise with us Next Article ArrayDeque spliterator() method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Collections Java - util package java-basics Java-Functions Java-ArrayDeque +2 More Practice Tags : JavaJava-Collections Similar Reads Java ArrayList spliterator() Method The spliterator() method in Java is used to iterate over the elements of an ArrayList. It provides a more efficient way to traverse the collection specially with parallel processing. This method is part of Java 8 and later.Example 1: Here, we will use the spliterator() method to loop through element 3 min read ArrayDeque pollFirst() Method in Java The java.util.ArrayDeque.pollFirst() method in Java is used to retrieve or fetch and remove the first element of the Deque. The peekFirst() method only retrieved the first element but the pollFirst() also removes the element along with the retrieval. It returns NULL if the deque is empty. Syntax: Ar 2 min read ArrayDeque pop() Method in Java The Java.util.ArrayDeque.pop() method in Java is used to pop an element from the deque. The element is popped from the top of the deque and is removed from the same. Syntax: Array_Deque.pop() Parameters: The method does not take any parameters. Return Value: This method returns the element present a 2 min read ArrayDeque pollLast() Method in Java The java.util.ArrayDeque.pollLast() method in Java is used to retrieve or fetch and remove the last element of the Deque. The peekLast() method only retrieved the element at the end but the pollLast() also removes the element along with the retrieval. It returns NULL if the deque is empty. Syntax: A 2 min read ArrayDeque peekLast() Method in Java The java.util.ArrayDeque.peekLast() method in Java is used to retrieve or fetch the last element of the deque. The element retrieved does not get deleted or removed from the Queue instead the method just returns it. If no element is present in the deque or it is empty, then Null is returned. Syntax: 2 min read Like