SKILL/JAVA

자바 Queue 기본 예제

Jedy_Kim 2017. 12. 19. 21:16
728x90
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
27
28
import java.util.LinkedList;
import java.util.Queue;
 
/*
 * Queue 
 * FIFO (First In First Out) 형태의 버퍼
 * public void offer(Element data);
 * public Element poll();
 * public Element peek();
 * public boolean empty();
 */
 
public class QueueMain {
    public static void main(String[] args) {
        Queue<String> q = new LinkedList<String>();
        q.offer("전효성");
        q.offer("아이유");
        q.offer("정우성");
        System.out.println(q.peek());
//        System.out.println(q.poll());
//        System.out.println(q.poll());
        
        q.offer("이효리");
        while(q.isEmpty() == false ) {
            System.out.println(q.poll());
        }
    }
}
cs


반응형

'SKILL > JAVA' 카테고리의 다른 글

자바 하노이의 탑 예제  (0) 2017.12.20
자바 메모리  (0) 2017.12.20
자바 Stack 기본예제  (0) 2017.12.19
자바 IP관련 클래스 : InetAddress  (0) 2017.12.19
자바 Vector연습예제  (0) 2017.12.19