本文介绍了LinkedList 在 Java 内部如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,链表的概念是一堆对象,它们通过具有下一个"和有时上一个"属性来遍历对象而相互连接.

As far as I know, the concept of a linked list is a bunch of object connected to each other by having a 'next' and sometimes 'previous' attribute to traverse the objects.

我注意到在 Java 中,您可以创建一个 LinkedList 对象……但是通过使用相同的方法(例如 .add()、.get() 等)将其视为数组/列表/序列.

I noticed in Java, you can create a LinkedList object...but treat it like an array/list/sequence by using the same methods such as .add(), .get(), etc.

那么,LinkedList 在内部是一个类似数组的序列吗?

So, is LinkedList internally an array-like sequence?

推荐答案

没有.它是一个私有嵌套类 Entry 的一系列实例,它具有 nextpreviouselement 引用.请注意,您可以通过查看 JDK 附带的源代码自己发现这一点.

No. It's a series of instances of a private nested class Entry, which has next, previous and element references. Note that you could have found this out yourself by looking at the source code, which comes with the JDK.

这个内部结构没有暴露的原因是它可以防止结构被破坏,例如包含一个循环.并且通过ListDeque 接口的统一访问允许多态使用.

The reason why this internal structure is not exposed is that it prevents the structure from becoming corrupted and e.g. containing a loop. And the uniform access via the List and Deque interfaces allows polymorphic use.

这篇关于LinkedList 在 Java 内部如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 23:49
查看更多