- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ArrayBlockingQueue Class in Java
A bounded blocking queue that is backed by an array is known as a ArrayBlockingQueue Class in Java. The size of the queue is fixed in the class and it uses FIFO for ordering elements. The ArrayBlockingQueue Class is a member of the Java Collections Framework.
A program that demonstrates this is given as follows −
Example
import java.util.concurrent.ArrayBlockingQueue; public class Demo { public static void main(String[] args) { int n = 10; ArrayBlockingQueue<Integer> abQueue = new ArrayBlockingQueue<Integer>(n); abQueue.add(7); abQueue.add(2); abQueue.add(6); abQueue.add(3); abQueue.add(1); System.out.println("The elements in ArrayBlockingQueue are: " + abQueue); } }
The output of the above program is as follows −
Output
The elements in ArrayBlockingQueue are: [7, 2, 6, 3, 1]
Now let us understand the above program.
The ArrayBlockingQueue is created with the capacity 10. Then elements are added to it and finally, it is displayed. A code snippet that demonstrates this is given as follows −
int n = 10; ArrayBlockingQueue<Integer> abQueue = new ArrayBlockingQueue<Integer>(n); abQueue.add(7); abQueue.add(2); abQueue.add(6); abQueue.add(3); abQueue.add(1); System.out.println("The elements in ArrayBlockingQueue are: " + abQueue);
Advertisements