LinkedLists in Collection interface are single or doubly.

huangapple go评论63阅读模式
英文:

What LinkedLists in Collection interface are single or doubly?

问题

我非常了解单向链表(SLL)或双向链表(DLL)的概念。
但是在集合(Collection)接口中,我们使用它们中的哪一个?

到目前为止,在接口List、Queue和Deque中,我遇到了LinkedList。

还有其他的吗?在这三个接口中,我们使用的是哪种类型的LinkedList?
我怎么能知道呢?

英文:

I very well understand the concept of SLL or DLL.
But which one of them are we using in Collection interface?

So far I have encountered LinkedList in interfaces List,Queue and Dequeue.

Is there any other? And what type of LinkedList are we using in these 3 interfaces?
How can I even know it?

答案1

得分: 3

List、Queue和Dequeue只是提供一个实现必须满足的接口。实现方式并不重要(事实上它甚至不一定是一个列表)。

LinkedList javadoc 的第一行说明如下:

List和Deque接口的双向链表实现。

英文:

List, Queue and Dequeue are just interfaces which provide a contract to be satisfied by the implementation. It doesn't matter how the list is implemented (in fact it doesn't even have to be a list).

The first line of LinkedList javadoc states
>Doubly-linked list implementation of the List and Deque interfaces.

答案2

得分: 0

所有的 Java 链表都是双向链表<br>

数组和数组列表有一个主要的缺点:从数组中间删除一个元素的代价太大。因为删除元素后,数组中所有在被删除元素之后的元素都必须被移动到数组的前面。(向数组中插入元素也是同样道理)<br>

然后 Java 提供了解决方案:<br>
Java 引入了链表来解决这个问题。在 Java 编程语言中,所有的链表实际上都是双向链表,在其中每个节点还存储着对前一个节点的引用。

英文:

All linked lists in java are doubly linked lists<br>

Arrays and array lists have a major disadvantage: Deleting an element from the middle of the array costs too much. Because all elements in the array after the deleted element must be moved to the front of the array. (The same goes for inserting an element into the array)<br>

And then Java deliver the solution:<br>
Java introduced a linked list to solve the problem. In the Java programming language, all linked lists are actually two-way linked, in which each node also stores a reference to the predecessor node.

huangapple
  • 本文由 发表于 2020年7月25日 21:43:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63089077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定