Java LinkedList - 检索操作之间的差异 [英] Java LinkedList - differences between retrieve operations
问题描述
在 LinkedList
中的以下每组元素检索操作中的不同方法之间是否有差异?
返回null +删除操作: poll()
, pollFirst()
p>
返回null +不删除操作 peek()
, peekFirst()
。
抛出异常+删除操作 pop() code>,
remove()
, removeFirst()
。
抛出异常+不删除操作 element()
, getFirst()
。
插入方法中存在类似的重复。
如果没有这样的区别,我会期望在javadoc中提到方法(像老旧的这就像调用... )。是否只是一个马虎的文档,或者我没有任何错误?
它们之间没有区别,文档也是,但你必须做一些递归搜索才能到达。
LinkedList
实现了两个接口 - c $ c> 和 的Deque
。而 Deque
从 Queue
延伸。
现在, Deque
已经定义了方法 - Deque#pollFirst()
并继承了该方法 - 队列#poll()
。
所以, LinkedList
基本上为它实现的两个接口定义了这两种方法。
关于这两种方法之间的相似性,它列在 Deque
为:
此接口扩展了Queue接口。当使用deque作为
队列时,FIFO(先进先出)行为的结果。元素在deque的末尾添加
,并从头开始删除。从Queue界面继承的方法
正好等同于Deque
方法,如下表所示:
还有一个表格列出了 Queue
类和等价的 Deque
方法的方法。请参阅 Deque#poll()
, Deque#peek()
例如他们清楚地列出了等效的方法。
Are there any differences between different methods in each of the following groups of element retrieve operations in LinkedList
?
Returning null + removing operations: poll()
, pollFirst()
.
Returning null + not removing operations: peek()
, peekFirst()
.
Throwing exception + removing operations: pop()
, remove()
, removeFirst()
.
Throwing exception + not removing operations: element()
, getFirst()
.
Similar duplications exists in insertion methods.
If there is no such difference, I would expect it to be mentioned in the javadoc of the methods (something like the good old "This is exactly like calling ..."). Is it only a sloppy documentation, or am I missing anything?
There is no difference between them, and it is listed in the documentation too, but you have to do some recursive searching to get there.
LinkedList
implements two interfaces - Queue
and Deque
. And Deque
extends from Queue
.
Now, Deque
has defined the method - Deque#pollFirst()
and inherited the method - Queue#poll()
.
So, LinkedList
has basically these two methods defined for the two interfaces it implements.
And about the similarity between those two methods, it is listed in documentation of Deque
as:
This interface extends the Queue interface. When a deque is used as a queue, FIFO (First-In-First-Out) behavior results. Elements are added at the end of the deque and removed from the beginning. The methods inherited from the Queue interface are precisely equivalent to Deque methods as indicated in the following table:
And there is a table listing the methods of Queue
class and the equivalent Deque
method. See Deque#poll()
, Deque#peek()
for e.g. They clearly list the equivalent method.
这篇关于Java LinkedList - 检索操作之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!