[JAVA] Queue 예제

정은아·2022년 7월 28일
package ja_0728;

import java.util.LinkedList;
import java.util.Queue;

public class Queue_1 {
	public static void main(String[] args) {
		
		int time = 10;
		Queue<Integer> qq = new LinkedList<>();
		

		for (int i = 1; i < time; i += 2) 
		{ 
			qq.offer(i);
		}
		
		System.out.println(qq.peek() + " aaa ");
		System.out.println(qq); 
		
		while(!qq.isEmpty())
		{
			System.out.println(qq.poll() + " aaa ");
			
			System.out.println(qq);
			
			try 
			{
				Thread.sleep(1000);
			} catch (InterruptedException e) 
			{
				e.printStackTrace();
			}
		}
	}
}

큐 안에 넣을 때에는 Queue명.offer(값);
큐에서 값을 빼낼 때에는 Queue명.poll();
poll() 대신 remove() 사용 가능

profile
꾸준함의 가치를 믿는 개발자

0개의 댓글