νμ ν¬κΈ°λ³΄λ€ λ°μ΄ν°λ₯Ό λ μ½μ νλ €κ³ ν λ offer λ©μλλ falseλ₯Ό λ°ννλ€. add λ©μλλ μλ¬λ₯Ό λ°ννλ€.
(1) LinkedList
import java.util.LinkedList;
import java.util.Queue;
public class Main {
public static void main(String[] args) {
Queue<Integer> queue = new LinkedList<>();
queue.add(1);
queue.add(2);
queue.add(3);
System.out.println(queue.peek()); // 1
System.out.println(queue.poll()); // 1
}
}
(2) PriorityQueue μ°μ μμν
: λ°μ΄ν°λ₯Ό μ½μ
ν λλ§λ€ μ°μ μμλ‘ μ λ ¬λλ ν
import java.util.PriorityQueue;
import java.util.Queue;
public class Main {
public static void main(String[] args) {
Queue<Integer> queue = new PriorityQueue<>();
queue.add(3);
queue.add(1);
queue.add(2);
System.out.println(queue.peek()); // 1 (κ°μ₯ μμ μμ)
System.out.println(queue.poll()); // 1
}
}