首页 > 其他 > 详细

Queue接口源码解析

时间:2016-07-17 00:57:16      阅读:214      评论:0      收藏:0      [点我收藏+]

队列
先进先出
入队列:offer
出队列:poll
队头元素:peek
继承:Collection抽象类
源码如下:


package java.util;

public interface Queue<E> extends Collection<E> {
    /**
     * 队列插入元素
     *
     * @param e the element to add
     * @return <tt>true</tt> (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);

    /**
     * 队列插入元素
     * 插入失败,抛出异常
     * @param e the element to add
     * @return <tt>true</tt> if the element was added to this queue, else
     *         <tt>false</tt>
     * @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);

    /**
     * 获取队顶元素,并删除该元素
     * 空的时候,抛出异常
     * @return the head of this queue
     * @throws NoSuchElementException if this queue is empty
     */
    E remove();

    /**
     * 获取队顶元素,并删除该元素
     * 空的时候,返回null
     * @return the head of this queue, or <tt>null</tt> if this queue is empty
     */
    E poll();

    /**
     * 查看队顶元素,但是不删除该元素、
     * 空的时候,抛出异常
     * @return the head of this queue
     * @throws NoSuchElementException if this queue is empty
     */
    E element();

    /**
     * 查看队顶元素,但是不删除该元素、
     * 空的时候,返回 null
     *
     * @return the head of this queue, or <tt>null</tt> if this queue is empty
     */
    E peek();
}

Queue接口源码解析

原文:http://blog.csdn.net/qunxingvip/article/details/51922593

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!