java 队列方法详解「建议收藏」

java 队列方法详解「建议收藏」一、队列支持的方法(Queue) throwexception returnspecialvalue insert add 1、增加元素不能为null 2、其他异常,比如有界队列 offer 1、元素不能为null 2、实现内部调用addF…

大家好,又见面了,我是你们的朋友全栈君。

一、队列支持的方法(Queue)

 

throw exception

return special value

insert

add

1、增加元素不能为null

2、其他异常,比如有界队列

offer

1、元素不能为null

2、实现内部调用addFirst,既也可能抛出异常

remove

remove

队列空时:NoSuchElementException

poll

队列空时:return null

examine

element

队列空时:NoSuchElementException

peek

队列空时:return null

 

二、双端队列(Deque)

        Deque继承自Queue接口,可以作为单端队列使用

 

队头操作(Head)

队尾操作(Tail)

 

throw exception

return special value

throw exception

return special value

Insert

addFirst

1、增加元素不能为null

2、其他异常,比如有界队列

offerFirst

1、元素不能为null

2、实现内部调用addFirst,既也可能抛出异常

addLast

同addFirst

offerLast

1、元素不能为null

2、实现内部调用addFirst,既也可能抛出异常

remove

romoveFirst

队列空时:NoSuchElementException

也就是说,使用时必须判空

pollFirst

队列空时:return null

removeLast

队列空时:NoSuchElementException

pollLast

队列空时:return null

examine

getFirst (变态,element成了get)

队列空时:NoSuchElementException

使用时必须判空

peekFirst

队列空时:return null

getLast

队列空时:NoSuchElementException

peekLast

队列空时:return null

三、栈

Deque定义了LIFO的栈操作

栈方法

内部调用

备注

push

 

addFirst

1、元素不能为空

2、可能抛出异常,内部调用的是addFirst

pop

removeFirst

队列空时,会抛出异常NoSuchElementException

peek

peekFirst

return special value

四、阻塞队列BlockingQueue

 

Throws exception

Special value

Blocks

Times out

insert

add(e)

offer(e)

put(e)

offer(e, time, unit)

remove

remove()

poll()

take()

poll(time, unit)

examine

element()

peek()

 

单词不够用了吧

五、队列框架图

脉络只是主要的继承或实现脉络,没有包括collection等相关的接口或类实现脉络

java 队列方法详解「建议收藏」

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/156656.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号