Published 2021. 5. 18. 16:48
Stack
Stack s = new Stack();
s.push("0");
s.push("1");
s.push("2");

while(!s.isEmpty()) {
	System.out.println(s.pop());
}
2
1
0
s.pop();
1
0
Queue
Queue q = new LinkedList();
q.offer("0");
q.offer("1");
q.offer("2");

while(!q.isEmpty()) {
	System.out.println(q.poll());
}
0
1
2
q.remove();
1
2
PriorityQueue
Queue pq = new PriorityQueue();
pq.offer(3);
pq.offer(1);
pq.offer(5);
pq.offer(2);
pq.offer(4);

Object obj = null;
while((obj = pq.poll()) != null) {
	System.out.println(obj);
}
1
2
3
4
5
pq.remove();
2
3
4
5
peek
Stack s = new Stack();
s.push("0");
s.push("1");
s.push("2");
s.pop();
System.out.println(s.peek());
1

stack의 맨위에 저장된 객체를 가져옴

복사했습니다!