Java LinkedList - 检索操作之间的差异 [英] Java LinkedList - differences between retrieve operations

查看:26
本文介绍了Java LinkedList - 检索操作之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LinkedList中以下各组元素检索操作的不同方法之间有什么区别吗?

Are there any differences between different methods in each of the following groups of element retrieve operations in LinkedList?

返回空值+移除操作: poll(), pollFirst().

返回 null + 不删除操作: peek(), peekFirst().

抛出异常+移除操作: pop(), remove(), removeFirst().

抛出异常+不删除操作: element(), getFirst().

插入方法中存在类似的重复.

Similar duplications exists in insertion methods.

如果没有这样的区别,我希望在方法的 javadoc 中提到它(类似于古老的这就像调用......"一样).它只是一个草率的文档,还是我遗漏了什么?

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 实现了两个接口- QueueDeque.而Deque 继承自Queue.

现在,Deque 已经定义了方法 - Deque#pollFirst() 并继承了该方法 - Queue#poll().

Now, Deque has defined the method - Deque#pollFirst() and inherited the method - Queue#poll().

所以,LinkedList 基本上为它实现的两个接口定义了这两个方法.

So, LinkedList has basically these two methods defined for the two interfaces it implements.

关于这两种方法之间的相似性,它列在的文档中Deque 为:

And about the similarity between those two methods, it is listed in documentation of Deque as:

这个接口扩展了Queue接口.当双端队列用作队列,FIFO(先进先出)行为结果.添加元素在双端队列的末尾并从开头删除.方法继承自 Queue 接口,正好等价于 Deque方法如下表所示:

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:

并且有一个表格列出了Queue 类的方法和等效的Deque 方法.请参阅Deque#poll(), Deque#peek() 例如他们清楚地列出了等效的方法.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆