前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java 队列方法详解「建议收藏」

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

作者头像
全栈程序员站长
发布2022-09-15 08:40:47
4860
发布2022-09-15 08:40:47
举报
文章被收录于专栏:全栈程序员必看

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

一、队列支持的方法(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 队列方法详解「建议收藏」
java 队列方法详解「建议收藏」

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年7月7,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、队列支持的方法(Queue)
  • 二、双端队列(Deque)
  • 三、栈
  • 四、阻塞队列BlockingQueue
  • 五、队列框架图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档