sitelink1 | https://blog.naver.com/rhrudwnszoq/222626952478 |
---|---|
sitelink2 | https://docs.oracle.com/javase/8/docs/ap...Queue.html |
sitelink3 | |
sitelink4 | |
sitelink5 | |
sitelink6 |
import java.util.LinkedList;
import java.util.Queue;
ublic class CacheEngine {
public static void main(String[] args) {
Queue<Integer> queue = new LinkedList<>();
for (int i = 1; i <= 10 ; i++) {
queue.offer (i); // input
System.out.println("Queue :" + queue);
}
// 1. 무한 루프 돌리기
// poll() 가장 첫번째로 입력한 데이터부터 반환
while (!queue.isEmpty()) { //비어있지 않으면 안일어난거임
System.out.println("POLL:" + queue.poll());
System.out.println("QUEUE: " + queue);
}
}
}
}
[Method]
boolean add(E e) - 넣기
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
E remove() - 꺼내기
Retrieves and removes the head of this queue.
E element() - 확인하기
Retrieves, but does not remove, the head of this queue.
boolean offer(E e) - 넣기, 넣을 공간이 부족하면 false 반환
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
E poll() - 꺼내기, 꺼낼 대상이 없으면 null 반환
Retrieves and removes the head of this queue, or returns null if this queue is empty.
E peek() - 확인하기. 확인할 데이터가 없으면 null 반환
Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.