简体   繁体   English

预定义的Java LinkedLists是否被双重链接?

[英]Are the predefined java LinkedLists Doubly linked?

Since there are methods in the java API for LinkedList such as: remove the last node, and insert a node at a specific index in the LinkedList.. the LinkedList in the API would have to be a doubly linked list, right? 由于Java API中有LinkedList的方法,例如:删除最后一个节点,并在LinkedList中的特定索引处插入一个节点。API中的LinkedList必须是一个双向链接列表,对吗?

I tried making my own single linked list but from what I found it was impossible to insert a node in a specific index and it was impossible to remove the last node in the list. 我尝试制作自己的单个链接列表,但从我发现的结果来看,不可能在特定索引中插入节点,也无法删除列表中的最后一个节点。 So if I wanted to do that, I should create my own doubly linked list? 因此,如果要这样做,应该创建自己的双向链表吗?

The java.util.LinkedList javadoc clearly states java.util.LinkedList javadoc明确指出

Doubly-linked list implementation of the List and Deque interfaces. List和Deque接口的双链接列表实现。

You need to declare your variable as a LinkedList to see its methods, like removeLast() . 您需要将变量声明为LinkedList才能查看其方法,例如removeLast()

LinkedList<String> linkedList = new LinkedList<>();
... // add stuff
linkedList.removeLast(); // compiles

List<String> list = new LinkedList<>();
... // add stuff
list.removeLast(); // doesn't compile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM