Queue接口继承自Collection接口。接口中的方法如下:
一、接口定义:
/**
* @since 1.5
* @author Doug Lea
* @param <E> the type of elements held in this collection
*/
public interface Queue<E> extends Collection<E> {
Queue接口是1.5版本以后才开始出现的,而且还是Doug Lea写的。
二、接口里规定的方法:
不包括继承自Collection的方法,总共有5个方法。
1、添加:
boolean add(E e);
add方法,如果添加成功,返回true, 如果队列已满,抛出异常。
boolean offer(E e);
offer添加成功,返回true, 如果队列已满,返回false。
2、删除队列头元素:
E remove();
删除并且返回头元素。如果队列为空,则抛出异常。
E poll();
删除并且返回头元素。如果队列为空,则返回null。
3、返回头元素:
E element();
返回但是不删除头元素,如果队列为空,则抛出异常。
E peek();
返回但是不删除头元素,如果队列为空,返回null。