ArrayBlockingQueue spliterator() method in Java Last Updated : 13 Dec, 2021 Comments Improve Suggest changes Like Article Like Report The spliterator() method of ArrayBlockingQueue return a Spliterator on the elements of ArrayBlockingQueue. The returned iterator is weakly consistent. Spliterator can be used with Streams in Java 8. Spliterator can traverse elements individually and in bulk too.Syntax: public Spliterator spliterator() Return Value: This method returns a Spliterator over the elements in ArrayBlockingQueue.Below programs illustrates spliterator() method of ArrayBlockingQueue class:Program 1: Java // Java Program Demonstrate spliterator() // method of ArrayBlockingQueue import java.util.concurrent.ArrayBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // define capacity of ArrayBlockingQueue int capacityOfQueue = 7; // create object of ArrayBlockingQueue ArrayBlockingQueue<Integer> Queue = new ArrayBlockingQueue<Integer>(capacityOfQueue); // Add element to ArrayBlockingQueue Queue.add(22); Queue.add(34); Queue.add(45); Queue.add(67); // create Spliterator of Queue // using spliterator() method Spliterator<Integer> numbers = Queue.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)); } } Output: Size of Spliterator : 4 list of Numbers: 22 34 45 67 Program 2: Java // Java Program Demonstrate spliterator() // method of ArrayBlockingQueue import java.util.concurrent.ArrayBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // define capacity of ArrayBlockingQueue int capacityOfQueue = 7; // create object of ArrayBlockingQueue ArrayBlockingQueue<String> QueueOfStrings = new ArrayBlockingQueue<String>(capacityOfQueue); // Add element to ArrayBlockingQueue QueueOfStrings.add("India"); QueueOfStrings.add("Pakistan"); QueueOfStrings.add("England"); QueueOfStrings.add("China"); QueueOfStrings.add("UAE"); QueueOfStrings.add("Spain"); // create Spliterator of QueueOfStrings // using spliterator() method Spliterator<String> listOfStrings = QueueOfStrings.spliterator(); // getExactSize of Spliterator System.out.println("Size of Spliterator : " + listOfStrings.estimateSize()); System.out.println("list of Country names:"); // forEachRemaining method of Spliterator listOfStrings.forEachRemaining((str) -> print(str)); } public static void print(String str) { System.out.println("Value = " + str); } } Output: Size of Spliterator : 6 list of Country names: Value = India Value = Pakistan Value = England Value = China Value = UAE Value = Spain Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ArrayBlockingQueue.html#spliterator-- Comment More infoAdvertise with us Next Article ArrayBlockingQueue spliterator() method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-ArrayBlockingQueue +1 More Practice Tags : JavaJava-Collections Similar Reads ArrayBlockingQueue Class in Java In Java, the ArrayBlockingQueue class is part of the java.util.concurrent package and implements the BlockingQueue interface. It is a thread-safe, bounded queue that helps manage producer-consumer scenarios by blocking threads when the queue is full or empty.The queue has a fixed size, specified dur 8 min read ArrayBlockingQueue add() method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 3 min read ArrayBlockingQueue clear() Method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework.Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue.The queue al 2 min read ArrayBlockingQueue contains() method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 3 min read ArrayBlockingQueue drainTo() Method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework.Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue.The queue al 5 min read ArrayBlockingQueue iterator() Method in Java The iterator() method of ArrayBlockingQueue class is used to returns an iterator of the same elements as this queue in a proper sequence. The elements returned from this method contains elements in order from first(head) to last(tail). The returned iterator is weakly consistent. Syntax: public Itera 2 min read ArrayBlockingQueue offer() Method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 6 min read ArrayBlockingQueue peek() Method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework.Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue.The queue al 2 min read ArrayBlockingQueue poll() Method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 4 min read ArrayBlockingQueue put() method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 2 min read Like