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  Âimportjava.util.Spliterator;importjava.util.concurrent.LinkedTransferQueue; ÂclassLinkedTransferQueueSpliteratorExample1 {    publicstaticvoidmain(String[] args)    {        // Initializing the queue        LinkedTransferQueue<String> queue =                    newLinkedTransferQueue<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  Âimportjava.util.Spliterator;importjava.util.concurrent.LinkedTransferQueue; ÂclassLinkedTransferQueueSpliteratorExample2 {    publicstaticvoidmain(String[] args)    {        // Initializing the queue        LinkedTransferQueue<Character> queue =                  newLinkedTransferQueue<Character>(); Â        // Adding elements to this queue        for(charch = '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


 
                                    







