일반 java.util.Queue

황제낙엽 2022.04.06 11:35 조회 수 : 11193

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.

 

 

 

image.png

 

번호 제목 글쓴이 날짜 조회 수
163 java.util.Optional 에서의 map() 함수의 이해 황제낙엽 2026.06.24 248
162 linux(ubuntu) 의 jdk 21 이 설정된 환경에서 jdk 17 로 다운그레이드 절차 황제낙엽 2025.09.22 1123
161 google-auth-library-oauth2-http 라이브러리 다운로드 황제낙엽 2023.11.19 3592
160 firebase-admin-java 라이브러리 다운로드 (firebase admin sdk library) 황제낙엽 2023.11.19 2354
159 Enum 활용 (개인블로그, Effective Java) file 황제낙엽 2023.11.02 2332
158 Enum 활용 (우아한기술블로그) file 황제낙엽 2023.11.02 2353
157 JPA 개요 황제낙엽 2023.07.25 2302
156 javax.mail 샘플 몇가지 (테스트 수행전) 황제낙엽 2023.06.26 2202
155 java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from naver / 테스트 성공) file 황제낙엽 2023.06.24 2283
154 java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from bing / 테스트 실패) [1] 황제낙엽 2023.06.23 2462
153 base64 encode, decode 황제낙엽 2023.06.12 2287
152 BASE64Encoder, BASE64Decoder 의 deprecated 황제낙엽 2023.06.12 2234
151 java로 알파벳 대소문자를 랜덤으로 조합하는 코드 만들어줘 (ChatGPT) 황제낙엽 2023.03.28 2219
150 구글 클라우드 비전 API 사용하기 (Google Cloud Vision API) 황제낙엽 2023.02.22 2056
149 람다식(Lambda Expressions in Java) file 황제낙엽 2022.12.03 3201
148 ConcurrentLinkedQueue와 LinkedBlockingQueue 황제낙엽 2022.04.06 2194
» java.util.Queue file 황제낙엽 2022.04.06 11193
146 HP-UX, IBM-AIX 황제낙엽 2021.06.23 2355
145 람다(Lambda)와 함수형 인터페이스 황제낙엽 2021.05.10 2200
144 for, while 등의 loop구문에서 sleep하기 황제낙엽 2020.12.04 2133