Queue接口源码解析

来源:互联网 发布:白知之明的读音是什么 编辑:程序博客网 时间:2024/04/28 02:02

队列
先进先出
入队列: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();}
0 0