大家好,又见面了,我是你们的朋友全栈君。
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继承自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 |
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等相关的接口或类实现脉络

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