java-ConcurrentLinkedQueue 简单使用

import java.util.concurrent.ConcurrentLinkedQueue;

public class CacheTest {
    /**
     *
     * offer(E e) 将指定元素插入此队列的尾部。
     * poll() 获取并移除此队列的头,如果此队列为空,则返回 null。
     * peek() 获取但不移除此队列的头;如果此队列为空,则返回 null。
     * remove(Object o) 从队列中移除指定元素的单个实例(如果存在)。
     * @param args
     */

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void main(String[] args) {
        ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue();
        queue.offer("哈哈哈");
        System.out.println("offer后,队列是否空?" + queue.isEmpty());
        System.out.println("从队列中poll:" + queue.poll());
        System.out.println("poll后,队列是否空?" + queue.isEmpty());

        queue.offer("哈哈哈");
        System.out.println("\noffer后,队列是否空?" + queue.isEmpty());
        System.out.println("从队列中peek:" + queue.peek());
        System.out.println("从队列中peek:" + queue.peek());
        System.out.println("从队列中peek:" + queue.peek());
        System.out.println("peek后,队列是否空?" + queue.isEmpty());

        queue.offer("哈哈哈");
        System.out.println("\noffer后,队列是否空?" + queue.isEmpty());
        System.out.println("从队列中remove已存在元素 :" + queue.remove("哈哈哈"));
        System.out.println("从队列中remove不存在元素:" + queue.remove("123"));
        System.out.println("remove后,队列是否空?" + queue.isEmpty());
    }

}

offer后,队列是否空?false
从队列中poll:哈哈哈
poll后,队列是否空?true

offer后,队列是否空?false
从队列中peek:哈哈哈
从队列中peek:哈哈哈
从队列中peek:哈哈哈
peek后,队列是否空?false

offer后,队列是否空?false
从队列中remove已存在元素 :true
从队列中remove不存在元素:false
remove后,队列是否空?false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值