ConcurrentLinkedQueue spliterator() method in Java Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The spliterator() method of ConcurrentLinkedQueue is used to get a Spliterator of the same elements as ConcurrentLinkedQueue. Created Spliterator is weakly consistent. 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 spliterator() Returns: This method returns a Spliterator over the elements in ConcurrentLinkedQueue. Below programs illustrate spliterator() method of ConcurrentLinkedQueue: Example 1: Java // Java Program Demonstrate spliterator() // method of ConcurrentLinkedQueue import java.util.concurrent.*; import java.util.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<Integer>(); // Add Numbers to queue queue.add(4353); queue.add(377139); queue.add(624378); queue.add(654793); queue.add(764764); queue.add(838494); queue.add(632845); // create Spliterator of ConcurrentLinkedQueue // using spliterator() method Spliterator<Integer> spt = queue.spliterator(); // print result from Spliterator System.out.println("list of Numbers:"); // forEachRemaining method of Spliterator spt.forEachRemaining((n) -> System.out.print(n + ", ")); } } Output: list of Numbers: 4353, 377139, 624378, 654793, 764764, 838494, 632845, Example 2: Java // Java Program Demonstrate spliterator() // method of ConcurrentLinkedQueue import java.util.concurrent.*; import java.util.*; public class GFG { public static void main(String[] args) { // create an ConcurrentLinkedQueue ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>(); // Add String to queue queue.add("Aman"); queue.add("Amar"); queue.add("Sanjeet"); queue.add("Rabi"); queue.add("Debasis"); queue.add("Raunak"); queue.add("Mahesh"); // create Spliterator of ConcurrentLinkedQueue // using spliterator() method Spliterator<String> spt = queue.spliterator(); // print result from Spliterator System.out.println("list of Strings:"); // forEachRemaining method of Spliterator spt.forEachRemaining((n) -> System.out.print(n + ", ")); } } Output: list of Strings: Aman, Amar, Sanjeet, Rabi, Debasis, Raunak, Mahesh, Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#spliterator-- Comment More infoAdvertise with us Next Article ConcurrentLinkedQueue spliterator() method in Java A AmanSingh2210 Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-ConcurrentLinkedQueue +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads ConcurrentLinkedQueue size() method in Java The size() method of ConcurrentLinkedQueue is used to returns number of elements that this ConcurrentLinkedQueue contains. Syntax: public int size() Returns: This method number of elements in this ConcurrentLinkedQueue. Below programs illustrate size() method of ConcurrentLinkedQueue: Example 1: Jav 2 min read ConcurrentLinkedQueue peek() method in Java The peek() method of ConcurrentLinkedQueue is used to return the head of the ConcurrentLinkedQueue. It retrieves but does not remove, the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method returns null. Syntax: public E peek() Returns: This method returns the 2 min read ConcurrentLinkedQueue poll() method in Java The poll() method of ConcurrentLinkedQueue is used to remove and return the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method will return null. Syntax: public E poll() Returns: This method remove and returns the head of this ConcurrentLinkedQueue or null if t 2 min read ConcurrentLinkedQueue toArray() Method in Java toArray() : The toArray() method of ConcurrentLinkedQueue is used to returns an array of the same elements as that of the ConcurrentLinkedQueue in proper sequence. Basically, it copies all the element from a ConcurrentLinkedQueue to a new array. This method behaves as a bridge between array and Conc 4 min read ConcurrentLinkedQueue offer() method in Java The offer() method of ConcurrentLinkedQueue is used to insert the element, passed as parameter, at the tail of this ConcurrentLinkedQueue. This method returns True if insertion is successful. ConcurrentLinkedQueue is unbounded, so this method offer() will never returns false. Syntax: public boolean 2 min read ConcurrentLinkedQueue remove() method in Java The remove(Object o) method of ConcurrentLinkedQueue is used to remove a single instance of the specified element from this ConcurrentLinkedQueue, if it is present. This method removes an element e such that o.equals(e) if this ConcurrentLinkedQueue contains one or more such elements. Remove() metho 2 min read ConcurrentLinkedDeque pollFirst() method in Java The java.util.concurrent.ConcurrentLinkedDeque.pollFirst() is an in-built method in Java which retrieves the first element of this deque and removes it. If the deque is empty, the method returns NULL. Syntax: Conn_Linked_Deque.pollFirst() Parameters: This function does not accepts any parameter. Ret 2 min read ConcurrentLinkedDeque peekLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.peekLast() is an in-built method in Java which retrieves the last element of this deque container without removing it. The function returns NULL if the deque is empty. Syntax: Conn_Linked_Deque.peekLast() Parameters: The function does not accepts any pa 2 min read ConcurrentLinkedDeque pollLast() method in Java The java.util.concurrent.ConcurrentLinkedDeque.pollLast() is an in-built method in Java which retrieves the last element of this deque and removes it. If the deque is empty, the method returns NULL. Syntax: Conn_Linked_Deque.pollLast() Parameters: The function accepts no parameters. Return Values:Th 2 min read ConcurrentSkipListSet spliterator() method in Java The java.util.concurrent.ConcurrentSkipListSet.spliterator() method is an in-built function in Java which returns a weakly uniform Spliterator across the elements of this set. Syntax: ConcurrentSkipListSet.spliterator() Parameters: The function does not accept any parameter. Return Value: The functi 2 min read Like