ArrayBlockingQueue iterator() Method in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 Iterator iterator() Return Value: The method returns the iterator having same elements as present in ArrayBlockingQueue in proper sequence. Below programs illustrates iterator() method of ArrayBlockingQueue class: Program 1: Java // Program Demonstrate how to apply iterator() method // of ArrayBlockingQueue Class. import java.util.concurrent.ArrayBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // Define capacity of ArrayBlockingQueue int capacity = 5; // Create object of ArrayBlockingQueue ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity); // Add 5 elements to ArrayBlockingQueue queue.offer(423); queue.offer(422); queue.offer(421); queue.offer(420); queue.offer(424); // Print queue System.out.println("Queue is " + queue); // Call iterator() method and Create an iterator Iterator iteratorValues = queue.iterator(); // Print elements of iterator System.out.println("\nThe iterator values:"); while (iteratorValues.hasNext()) { System.out.println(iteratorValues.next()); } } } Output: Queue is [423, 422, 421, 420, 424] The iterator values: 423 422 421 420 424 Program 2: Java // Program Demonstrate how to apply iterator() method // of ArrayBlockingQueue Class. import java.util.concurrent.ArrayBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // Define capacity of ArrayBlockingQueue int capacity = 5; // Create object of ArrayBlockingQueue ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<String>(capacity); // Add 5 elements to ArrayBlockingQueue queue.offer("User"); queue.offer("Employee"); queue.offer("Manager"); queue.offer("Analyst"); queue.offer("HR"); // Print queue System.out.println("Queue is " + queue); // Call iterator() method and Create an iterator Iterator iteratorValues = queue.iterator(); // Print elements of iterator System.out.println("\nThe iterator values:"); while (iteratorValues.hasNext()) { System.out.println(iteratorValues.next()); } } } Output: Queue is [User, Employee, Manager, Analyst, HR] The iterator values: User Employee Manager Analyst HR Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ArrayBlockingQueue.html#iterator Create Quiz Comment A AmanSingh2210 Follow 0 Improve A AmanSingh2210 Follow 0 Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-ArrayBlockingQueue +1 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like