ArrayBlockingQueue toString() Method in Java Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The toString() method of ArrayBlockingQueue class is used to get a string representation of the objects of ArrayBlockingQueue. The string of ArrayBlockingQueue contains elements of ArrayBlockingQueue in the order from first(head) to last(tail), enclosed in square brackets("[]"). The elements are separated by the characters", " (comma and a space). So basically the toString() method is used to convert all the elements of ArrayBlockingQueue into a String. Syntax: public String toString() Return Value: The method returns an String representation of ArrayBlockingQueue. Below programs illustrates toString() method of ArrayBlockingQueue class: Program 1: Java // Program to demonstrate how to apply toString() method // of ArrayBlockingQueue Class. import java.util.concurrent.ArrayBlockingQueue; 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 toString() method and Create an iterator String stringRepresentation=queue.toString(); // Print String value returned by toString() method System.out.println("\nThe String returned by toString():"); System.out.println(stringRepresentation); } } Output: Queue is [423, 422, 421, 420, 424] The String returned by toString(): [423, 422, 421, 420, 424] Program 2: Java // Program Demonstrate how to apply toString() method // of ArrayBlockingQueue Class. import java.util.concurrent.ArrayBlockingQueue; public class GFG { public static void main(String[] args) { // Define capacity of ArrayBlockingQueue int capacity = 10; // 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"); queue.offer("Tester"); // Print queue System.out.println("Queue is "+queue); // Call toString() method and Create an iterator String stringRepresentation=queue.toString(); // Print String value returned by toString() method System.out.println("\nThe String returned by toString():"); System.out.println(stringRepresentation); } } Output: Queue is [User, Employee, Manager, Analyst, HR, Tester] The String returned by toString(): [User, Employee, Manager, Analyst, HR, Tester] Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ArrayBlockingQueue.html#toString Comment More infoAdvertise with us Next Article ArrayBlockingQueue toString() 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