定义


队列是一种特殊的线性表,它只允许在表的前端进行删除操作,而在表的后端进行插入操作。

LinkedList类实现了Queue接口,因此我们可以把LinkedList当成Queue来用

图例


Queue本身是一种先入先出的模型(FIFO),和我们日常生活中的排队模型很类似。根据不同的实现,他们主要有数组和链表两种实现形式。如下图:

与队列相关的类的关系图如下:

常用方法


序号 方法名 描述
1 boolean add(E e) 将指定的元素插入到队列中。
2 Object element() 检索该队列的头。
  boolean offer(E e) 将指定元素插入到该队列中(在该队列容量之内)。
3 Object peek() 检索该队列的头,如果该队列为空返回null。
4 Object poll() 检索并删除该队列的头,如果该队列为空返回null。
5 Object remove() 检索并删除该队列的头。

源码


 package java.util;

 public interface Queue<E> extends Collection<E> {
/**
* Inserts the specified element into this queue if it is possible to do so
* immediately without violating capacity restrictions, returning
* {@code true} upon success and throwing an {@code IllegalStateException}
* if no space is currently available.
*
* @param e the element to add
* @return {@code true} (as specified by {@link Collection#add})
* @throws IllegalStateException if the element cannot be added at this
* time due to capacity restrictions
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue
* @throws NullPointerException if the specified element is null and
* this queue does not permit null elements
* @throws IllegalArgumentException if some property of this element
* prevents it from being added to this queue
*/
boolean add(E e); /**
* Inserts the specified element into this queue if it is possible to do
* so immediately without violating capacity restrictions.
* When using a capacity-restricted queue, this method is generally
* preferable to {@link #add}, which can fail to insert an element only
* by throwing an exception.
*
* @param e the element to add
* @return {@code true} if the element was added to this queue, else
* {@code false}
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this queue
* @throws NullPointerException if the specified element is null and
* this queue does not permit null elements
* @throws IllegalArgumentException if some property of this element
* prevents it from being added to this queue
*/
boolean offer(E e); /**
* Retrieves and removes the head of this queue. This method differs
* from {@link #poll poll} only in that it throws an exception if this
* queue is empty.
*
* @return the head of this queue
* @throws NoSuchElementException if this queue is empty
*/
E remove(); /**
* Retrieves and removes the head of this queue,
* or returns {@code null} if this queue is empty.
*
* @return the head of this queue, or {@code null} if this queue is empty
*/
E poll(); /**
* Retrieves, but does not remove, the head of this queue. This method
* differs from {@link #peek peek} only in that it throws an exception
* if this queue is empty.
*
* @return the head of this queue
* @throws NoSuchElementException if this queue is empty
*/
E element(); /**
* Retrieves, but does not remove, the head of this queue,
* or returns {@code null} if this queue is empty.
*
* @return the head of this queue, or {@code null} if this queue is empty
*/
E peek();
}

参考:http://blog.csdn.net/u010617952/article/details/51726789

最新文章

  1. linux 下查看cpu位数 内核等参数命令(转)
  2. 自己封装一个Log模块
  3. Kylin的cube模型
  4. VS.net 2013中使用Git建立源代码管理 版本管理
  5. IP地址查询API的C#实现
  6. Timing advance of GSM(时间提前量)
  7. ASP.NET MVC 学习6、学习使用Code First Migrations功能,把Model的更新同步到DB中
  8. Get与POST的理解
  9. Git配合Tag的代码回滚
  10. javascript Dom 编程
  11. pyqt5 动画学习(三) 指定控件的移动轨迹
  12. webpack4.0各个击破(5)—— Module篇
  13. Linux+Shell常用命令总结
  14. Linux系统安装与初用
  15. 洛谷P4546 [THUWC2017]在美妙的数学王国中畅游 [LCT,泰勒展开]
  16. db2pd工具
  17. [LeetCode&amp;Python] Problem 401. Binary Watch
  18. linux问题集
  19. 【转】Java类成员变量默认初始化规则
  20. windows 中 到底是用的哪个java.exe??? 删除了PATH变量的Java设置还是可以运行java.exe windows/system32

热门文章

  1. 利用DOCKER实现云桌面的开发环境初步设想
  2. 1.HTTP与HTTPS区别
  3. ApacheDbUtilsUpdate
  4. 学习java时在要求输出的数字带俩个小数点时,利用String.format时出现的问题
  5. heap(堆)
  6. Django学习 之 Django安装与一个简单的实例认识
  7. hbase meta中分区信息错误的记录
  8. 视图家族 &amp; 路由组件
  9. java学习-初级入门-面向对象④-类与对象-类与对象的定义和使用2
  10. 如何通过DICOM的tag来判断3D图像的方向