-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCarQueue.java
More file actions
26 lines (22 loc) · 766 Bytes
/
CarQueue.java
File metadata and controls
26 lines (22 loc) · 766 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
import java.util.LinkedList;
import java.util.Queue;
public class CarQueue {
public static void main(String[] args) {
Queue<String> carQueue = new LinkedList<>();
carQueue.add("BMW");
carQueue.add("Toyota");
carQueue.add("Honda");
System.out.println("Queue: " + carQueue);
String firstCar = carQueue.poll();
System.out.println("Queue: " + carQueue);
String secondCar = carQueue.poll();
System.out.println("Queue: " + carQueue);
String thirdCar = carQueue.poll();
System.out.println("Queue: " + carQueue);
if (carQueue.isEmpty()) {
System.out.println("Empty.");
} else {
System.out.println("Not Empty.");
}
}
}