GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • ArrayBlockingQueue
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — ArrayBlockingQueue remove() method in Java - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

ArrayBlockingQueue remove() method in Java

Last Updated : 11 Jul, 2025
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 remove(Object o) method removes a single instance of the specified element from this queue, if it is present. We can say that method removes an element e such that o.equals(e) if this queue contains one or more such elements. Remove() method returns true if this queue contained the specified element which we want to remove. Syntax:
public boolean remove(Object o)
Parameter: o - element to be removed from this queue, if present. Returns: returns true if this queue contained the specified element which we want to remove. Below program illustrate remove(Object o) method of ArrayBlockingQueue. Example 1 Java
// Java Program Demonstrate remove(Object o)
// 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);

        // print Queue
        System.out.println("queue contains " + queue);

        // remove 223
        boolean response = queue.remove(223);
        // print Queue
        System.out.println("Removal of 223 :" + response);

        // print Queue
        System.out.println("queue contains " + queue);

        // remove 546
        response = queue.remove(546);
        // print Queue
        System.out.println("Removal of 546 :" + response);

        // print Queue
        System.out.println("queue contains " + queue);

        // remove 734 which is not present
        response = queue.remove(734);
        // print Queue
        System.out.println("Removal of 734 :" + response);

        // print Queue
        System.out.println("queue contains " + queue);
    }
}
Output :
queue contains [223, 546, 986]
Removal of 223 :true
queue contains [546, 986]
Removal of 546 :true
queue contains [986]
Removal of 734 :false
queue contains [986]
Example 2 Java
// Java Program Demonstrate remove(Object o)
// 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 StarWars
        boolean response = queue.remove("StarWars");
        // print Queue
        System.out.println("Removal of StarWars :" + response);

        // print Queue
        System.out.println("queue contains " + queue);

        // remove Hulk
        response = queue.remove("Hulk");
        // print Queue
        System.out.println("Removal of Hulk :" + response);

        // print Queue
        System.out.println("queue contains " + queue);
    }
}
Output :
queue contains [StarWars, SuperMan, Flash, BatMan, Avengers]
Removal of StarWars :true
queue contains [SuperMan, Flash, BatMan, Avengers]
Removal of Hulk :false
queue contains [SuperMan, Flash, BatMan, Avengers]
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ArrayBlockingQueue.html#remove(java.lang.Object)
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.