码迷,mamicode.com
首页 > 其他好文 > 详细

Queue接口源码解析

时间:2016-07-17 00:58:15      阅读:142      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!