일반 java.util.Queue

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

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

 

번호 제목 글쓴이 날짜 조회 수
331 ajax 로 post 데이터를 servlet 으로 전달 받기 (with nexacro) [1] secret 황제낙엽 2023.02.26 0
330 구글 클라우드 비전 API 사용하기 (Google Cloud Vision API) 황제낙엽 2023.02.22 8
329 람다식(Lambda Expressions in Java) file 황제낙엽 2022.12.03 2
328 ConcurrentLinkedQueue와 LinkedBlockingQueue 황제낙엽 2022.04.06 17
» java.util.Queue file 황제낙엽 2022.04.06 5381
326 숫자형 클래스 BigInterger (int, long 범위 초과) 황제낙엽 2022.01.16 368
325 LocalDate.now() 오늘 날짜 황제낙엽 2022.01.16 7
324 HttpServletRequest, HttpServletResponse, JSONObject, POST 황제낙엽 2022.01.12 31
323 [java.lang.ProcessBuilder] “매개변수가 틀립니다” 혹은 ”Cannot run program” 황제낙엽 2021.10.15 191
322 특정 경로에서 쉘 명령어 실행하기 (ProcessBuilder) 황제낙엽 2021.10.08 54
321 HP-UX, IBM-AIX 황제낙엽 2021.06.23 55
320 nashorn ScriptEninge Test Project (war) file 황제낙엽 2021.05.19 157
319 람다(Lambda)와 함수형 인터페이스 황제낙엽 2021.05.10 19
318 javax.script.ScriptEngine 관련 참고사항 (sample java 포함) 황제낙엽 2021.05.09 463
317 Java Scripting API: GraalVM 적용해보기 황제낙엽 2021.05.09 23
316 Java Scripting API: 바인딩과 스크립트 컨텍스트 그리고 실행 성능 개선 file 황제낙엽 2021.05.09 15
315 Java Scripting API: 자바에서 자바스크립트의 함수를 호출할 수 있을까? file 황제낙엽 2021.05.09 345
314 Java에서 Nashorn JavaScript 엔진 사용 file 황제낙엽 2021.05.09 230
313 [JSP] 파일 다운로드 테스트 file 황제낙엽 2021.04.12 123
312 ResultSet 을 순회하기 전에 사이즈 구하기 황제낙엽 2021.01.14 28