데이터를 저장하고 관리하는 선형 자료구조
add(element)
요소를 큐에 추가하고, 큐가 꽉 차 있으면 예외를 던진다
poll()
요소를 제거하고, 큐가 비어 있으면 null을 반환한다
peek()
요소를 반환하고, 큐가 비어 있으면 null을 반환한다
isEmpty()
큐가 비어 있는지 여부를 확인한다
비어있으면 true를 반환하고, 그렇지 않으면 false를 반환한다
import java.util.Queue;
import java.util.LinkedList;
public class QueueExample {
public static void main(String[] args) {
Queue<String> queue = new LinkedList<>();
// add
queue.add("Alice");
queue.add("Bob");
queue.add("Charlie");
// poll
String frontElement = queue.poll(); // frontElement will be "Alice"
System.out.println("Dequeued: " + frontElement);
// peek
String peekedElement = queue.peek(); // peekedElement will be "Bob"
System.out.println("Peeked: " + peekedElement);
// isEmpty
boolean isEmpty = queue.isEmpty(); // isEmpty will be false
System.out.println("Is empty: " + isEmpty);
}
}