java 队列方法详解

一、队列支持的方法(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等相关的接口或类实现脉络

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值