Java ArrayBlockingQueue Adding Elements

PreviousNext

The add(E e) method inserts the element passed as a parameter to the method at the tail of this queue.

Java Program to Demonstrate adding elements to an ArrayBlockingQueue.

import java.util.concurrent.ArrayBlockingQueue;

public class Main {

    public static void main(String[] args) {
        // define capacity of ArrayBlockingQueue
        int capacity = 15;

        // create object of ArrayBlockingQueue
        ArrayBlockingQueue<Integer> abq = 
         new ArrayBlockingQueue<Integer>(capacity);

        // add  numbers
        abq.add(1);
        abq.add(2);
        abq.add(3);

        System.out.println("ArrayBlockingQueue:" + abq);
    }
}

Result

PreviousNext

Related