集合框架(四)Queue

Queue(I)

队列接口

  • 特点

    1. 先进先出
  • 常用特有方法

    1. offer() 入队

      queue.offer("one");
      queue.offer("two");
      queue.offer("three");
      System.out.println(queue);
      // [one, two, three]
      
    2. poll() 出队(移除队列的头)

      System.out.println(queue);
      queue.poll();
      System.out.println(queue);
      // [one, two, three]
      // [two, three]
      
    3. peek() 出队(不移除队列的头)

      System.out.println(queue);
      queue.peek();
      System.out.println(queue);
      // [one, two, three]
      // [one, two, three]
      
  • 常用实现类

    LinkedList

  • 子接口

    Deque

    双端队列,也可以作为栈

    • 特点

      1. 作为双端队列 --> 先进先出
      2. 作为栈 --> 后进先出
    • 常用特有方法

      • 双端队列
        1. offerFirst()
        2. offerLast()
        3. pollFirst()
        4. pollLast()
      • 栈 (与Stack类似)
        1. push() 压栈
        2. pop() 弹栈(移除栈顶对象)
    • 常用实现类

      LinkedList

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值