Interface Queue

Queue队列继承了Collection接口,并扩展了队列相关方法

添加到队尾,取/删除从对头。

boolean add(E e);

复写,在队列尾部添加,会多抛一个异常

boolean offer(E e);

扩展,也是在队列尾部添加,只是不会抛出异常

IllegalStateException* when no space is currently available.

E remove();

读取队列头部元素然后移除,抛出异常:NoSuchElementException if this queue is empty

E poll();

读取队列头部元素然后移除,返回null if this queue is empty

E element();

返回队列头部元素,抛出异常:NoSuchElementException if this queue is empty

E peek();

返回队列头部元素,返回null if this queue is empty

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容