ArrayBlockingQueue put() method in Java Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report 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 also follows FIFO (first-in-first-out) rule for storing and removing elements from the queue. If you try to put an element into a full queue or to take an element from an empty queue then the queue will block you. The put (E e) method inserts element passed as parameter to method at the tail of this queue(ArrayBlockingQueue) if queue is not full. If the queue is full then it will wait for space to become available. Syntax: public void put(E e) throws InterruptedException Parameter: e - the element to add in queue. Throws InterruptedException - if interrupted while waiting. NullPointerException - if the specified element is null. Below programs illustrate put(E e) method of ArrayBlockingQueue. Example 1 Java // Java Program to demonstrate put(E e) // method of ArrayBlockingQueue. import java.util.concurrent.ArrayBlockingQueue; public class GFG { public static void main(String[] args) throws InterruptedException { // define capacity of ArrayBlockingQueue int capacity = 5; // create object of ArrayBlockingQueue ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity); // Add elements to ArrayBlockingQueue using put method queue.put(223); queue.put(546); queue.put(986); queue.put(357); queue.put(964); // print Queue System.out.println("queue contains " + queue); } } Output : queue contains [223, 546, 986, 357, 964] Example 2 Java // Java Program to demonstrate put(E e) // method of ArrayBlockingQueue import java.util.concurrent.ArrayBlockingQueue; public class GFG { public static void main(String[] args) throws InterruptedException { // define capacity of ArrayBlockingQueue int capacity = 5; // create object of ArrayBlockingQueue ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<String>(capacity); // Add elements to ArrayBlockingQueue using put method queue.put("StarWars"); queue.put("SuperMan"); queue.put("Flash"); queue.put("BatMan"); queue.put("Avengers"); // print Queue System.out.println("queue contains " + queue); // remove some elements queue.remove(); queue.remove(); // Add elements to ArrayBlockingQueue using put method queue.put("CaptainAmerica"); queue.put("Thor"); System.out.println("queue contains " + queue); } } Output : queue contains [StarWars, SuperMan, Flash, BatMan, Avengers] queue contains [Flash, BatMan, Avengers, CaptainAmerica, Thor] Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ArrayBlockingQueue.html#put(E) Comment More infoAdvertise with us A AmanSingh2210 Follow Improve Article Tags : Java Java-Collections Java - util package Java-lang package Java-Functions Java-ArrayBlockingQueue +2 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