Java中的列表、链表、数组列表
关于List、Linkedlist和Arraylist,哪一种是单向链表,哪一种是双向链表? 我们怎样才能扭转它呢?
About the List, Linkedlist and Arraylist, which one is a one way list and which one is Doubly-linked list?
And how could we reverse it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
列表
一个仅定义列表行为的接口。
ArrayList
< /a>List
实现,由数组支持。它不是链接列表。LinkedList
< /a>List
实现,由 双向链表。如果你想要一个单链表,你必须自己编写。
我应该指出,制作一个实现 的单个链表
java.util.List
并不容易。它要求您有一个ListIterator;
,并且ListIterator
规范的一部分是您可以使用方法hasPrevious
,上一页
和 上一个索引。因此,要保持它的高效性和忠实于单链表的口头禅将是非常困难的。List
An interface that merely defines behavior of lists.
ArrayList
A
List
implementation, backed by an array. It is not a linked list.LinkedList
A
List
implementation, backed by an implementation of a doubly-linked list.If you want a single-linked list, you'll have to write it yourself.
I should point out that making a single linked list that implements
java.util.List
is not easy. It requires you to have aListIterator<E>
, and part of theListIterator
specification is that you can traverse in either direction with methodshasPrevious
,previous
, and previousIndex. So to keep it both efficient and true to the single linked list mantra would be very difficult.您可以使用
Collections.reverse(..)
反转任何集合。LinkedList
(以及任何Deque
)都有descendingIterator()
You can reverse any collection using
Collections.reverse(..)
.LinkedList
(and anyDeque
) hasdescendingIterator()