The java.util.concurrent.LinkedTransferQueue.spliterator() method is an in-built function in Java which returns a weakly uniform Spliterator across the elements of this queue.
Syntax:
LinkedTransferQueue.spliterator()
Parameters: The function does not accept any parameter.
Return Value: The function returns a Spliterator across the elements of this queue.
Below programs illustrate the LinkedTransferQueue.spliterator() method:
Program 1:
// Java Program Demonstrate Spliterator() // method of LinkedTransferQueue import java.util.Spliterator; import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueSpliteratorExample1 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<String> queue = new LinkedTransferQueue<String>(); // Adding elements to this queue queue.add("Gfg"); queue.add("is"); queue.add("best!!"); // spliterator split and iterate // the split parts in parallel Spliterator<String> str = queue.spliterator(); // performs the action for each remaining element str.forEachRemaining( (n) -> { String lc = n.toUpperCase(); System.out.println(" Lower case = " + n); System.out.println(" Upper case = " + lc); System.out.println(); }); } } |
Lower case = Gfg Upper case = GFG Lower case = is Upper case = IS Lower case = best!! Upper case = BEST!!
Program 2:
// Java Program Demonstrate Spliterator() // method of LinkedTransferQueue import java.util.Spliterator; import java.util.concurrent.LinkedTransferQueue; class LinkedTransferQueueSpliteratorExample2 { public static void main(String[] args) { // Initializing the queue LinkedTransferQueue<Character> queue = new LinkedTransferQueue<Character>(); // Adding elements to this queue for (char ch = 'A'; ch <= 'Z'; ch++) { queue.add(ch); } // Printing elements in the queue System.out.print("The elements in the queue are : "); // spliterator split and iterate // the split parts in parallel Spliterator<Character> str = queue.spliterator(); // if element exists tryAdvance() will perform action while (str.tryAdvance((n) -> System.out.print(n + " "))) ; } } |
The elements in the queue are : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- CopyOnWriteArrayList spliterator() method in Java
- CopyOnWriteArraySet spliterator() method in Java
- PriorityQueue spliterator() method in Java
- ArrayDeque spliterator() method in Java
- PriorityBlockingQueue spliterator() method in Java
- ConcurrentSkipListSet spliterator() method in Java
- ArrayBlockingQueue spliterator() method in Java
- LinkedBlockingDeque spliterator() method in Java
- ArrayList spliterator() method in Java
- LinkedList spliterator() method in Java
- HashSet spliterator() method in Java
- ConcurrentLinkedQueue spliterator() method in Java
- LinkedTransferQueue put() method in Java
- LinkedTransferQueue contains() method in Java
- LinkedTransferQueue take() method in Java
- LinkedTransferQueue add() method in Java
- ConcurrentLinkedDeque Spliterator() method in Java with Examples
- Java 8 | LinkedBlockingQueue spliterator() method with Examples
- LinkedTransferQueue poll() method in Java
- LinkedTransferQueue hasWaitingConsumer() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

