ArrayBlockingQueue put() method in Java


The put() method of the ArrayBlockingQueue class inserts the specified element at the tail of this queue. It waits for the space to become available, if the queue is full.

The syntax is as follows:

void put(E e)

Here, e is the element to be inserted.

To work with ArrayBlockingQueue class, you need to import the following package:

import java.util.concurrent.ArrayBlockingQueue;

The following is an example to implement put() method of Java ArrayBlockingQueue class:

Example

 Live Demo

import java.util.concurrent.ArrayBlockingQueue;
public class Demo {
   public static void main(String[] args) throws InterruptedException {
      ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<Integer>(7);
      q.put(200);
      q.put(310);
      q.put(400);
      q.put(450);
      q.put(500);
      q.put(550);
      q.put(700);
      System.out.println("ArrayBlockingQueue = " + q);
   }
}

Output

ArrayBlockingQueue = [200, 310, 400, 450, 500, 550, 700]

Updated on: 30-Jul-2019

53 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements