-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCarQueue.java
More file actions
29 lines (24 loc) · 840 Bytes
/
CarQueue.java
File metadata and controls
29 lines (24 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.LinkedList;
import java.util.Queue;
public class CarQueue {
public static void main(String[] args) {
Queue<String> carQueue = new LinkedList<>();
// Adding cars to the queue
carQueue.add("Car 1");
carQueue.add("Car 2");
carQueue.add("Car 3");
carQueue.add("Car 4");
System.out.println("Cars in the queue:");
System.out.println(carQueue);
// Removing cars from the queue
while (!carQueue.isEmpty()) {
System.out.println("Removing: " + carQueue.remove());
}
// Checking if the queue is empty
if (carQueue.isEmpty()) {
System.out.println("The queue is now empty.");
} else {
System.out.println("The queue is not empty.");
}
}
}