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 peek() method is used to return the head of the queue. It retrieves but does not remove, the head of this queue. If the queue is empty then this method returns null.
public E peek()
Parameters: The method does not take any parameters.
Return Value: The method returns the element present at the head of this queue.
Below programs illustrate peek() method of ArrayBlockingQueue.
After addding numbers queue is [23, 32, 45, 12] Head of queue 23
Details of First User Inserted User Name : Aman User Age : 24
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- PriorityQueue peek() Method in Java
- ArrayDeque peek() Method in Java
- Stack peek() Method in Java
- LinkedBlockingQueue peek() method in Java
- PriorityBlockingQueue peek() method in Java
- LinkedBlockingDeque peek() method in Java
- LinkedTransferQueue peek() method in Java
- ConcurrentLinkedQueue peek() method in Java
- Queue peek() method in Java
- ConcurrentLinkedDeque peek() method in Java with Example
- DelayQueue peek() method in Java with Examples
- BlockingDeque peek() method in Java with examples
- ArrayBlockingQueue add() method in Java
- ArrayBlockingQueue toString() Method in Java
- ArrayBlockingQueue size() Method in Java
- ArrayBlockingQueue poll() Method in Java
- ArrayBlockingQueue put() method in Java
- ArrayBlockingQueue remove() method in Java
- ArrayBlockingQueue contains() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.