thread37
来源:互联网 发布:csol永恒python属性 编辑:程序博客网 时间:2024/05/02 16:24
package com.neutron.t22;import java.util.Queue;import java.util.concurrent.ConcurrentLinkedDeque;import java.util.concurrent.ConcurrentLinkedQueue;/** * 单向和双向队列 */public class T224Queue { public static void main(String[] args) { // 单向队列 Queue<String> queue = new ConcurrentLinkedQueue<>(); // 双向队列 Queue<String> deque = new ConcurrentLinkedDeque<>(); for (int i = 0; i < 10; i++) { queue.offer("a" + i); // 等价于add } System.out.println("list size:" + queue.size()); System.out.println(queue.poll()); // get and remove System.out.println("list size:" + queue.size()); System.out.println(queue.peek()); // get not remove System.out.println("list size:" + queue.size()); }}