Skip to content

Commit bbd93f8

Browse files
committed
feat: add QueueInterfaceDemo illustrating Java Queue operations and behavior
Implemented QueueInterfaceDemo.java demonstrating FIFO operations using LinkedList and ArrayBlockingQueue. Covers key Queue methods (add, offer, remove, poll, peek) and contrasts bounded vs unbounded queue behavior. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent b641cbd commit bbd93f8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Section 25 Collections Frameworks/Queue Interface/src/QueueInterfaceDemo.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
import java.util.Queue;
33
import java.util.concurrent.ArrayBlockingQueue;
44

5-
/* QueueInterface
6-
* This class demonstrates how the Queue interface works in Java
7-
* using two implementations:
8-
* 1. LinkedList (unbounded queue).
9-
* 2. ArrayBlockingQueue (bounded queue with fixed capacity).
10-
11-
* Queue follows FIFO (First In, First Out).
12-
* Key methods: add(), offer(), remove(), poll(), element(), peek().
13-
*/
14-
155
public class QueueInterfaceDemo {
166
public static void main(String[] args) {
17-
// ---------------- Queue with LinkedList ----------------
7+
// Queue with LinkedList
188
Queue<Integer> queue1 = new LinkedList<>();
199

2010
// Add elements (FIFO order).
2111
queue1.add(1);
2212
queue1.add(3);
2313
queue1.add(2);
14+
queue1.add(4);
2415

2516
System.out.println("Queue1 (LinkedList) contents: " + queue1);
2617
System.out.println("Queue1 size: " + queue1.size());
@@ -38,7 +29,7 @@ public static void main(String[] args) {
3829
System.out.println("Peeking head element: " + queue1.peek());
3930

4031

41-
// ---------------- Queue with ArrayBlockingQueue ----------------
32+
// Queue with ArrayBlockingQueue
4233
// ArrayBlockingQueue is a bounded blocking queue with fixed capacity.
4334
Queue<Integer> queue2 = new ArrayBlockingQueue<>(2);
4435

@@ -56,6 +47,16 @@ public static void main(String[] args) {
5647
}
5748

5849
/*
50+
QueueInterface
51+
This class demonstrates how the Queue interface works in Java
52+
53+
using two implementations:
54+
1. LinkedList (unbounded queue).
55+
2. ArrayBlockingQueue (bounded queue with fixed capacity).
56+
57+
Queue follows FIFO (First In, First Out).
58+
Key methods: add(), offer(), remove(), poll(), element(), peek().
59+
5960
1. Queue Interface:
6061
- Part of java.util package.
6162
- Represents a collection designed for holding elements prior to processing (FIFO).
@@ -111,5 +112,4 @@ ASCII Example (FIFO):
111112
Enqueue 1: [1]
112113
Enqueue 2: [1,2]
113114
Offer 3: fails (capacity full) → [1,2]
114-
115115
*/

0 commit comments

Comments
 (0)