Why is LinkedList in Java not a real Linked List?

By definition, a Linked List is a list in which each of its elements refers to the next element (and the previous element, if we are talking about a double linked list). http://en.wikipedia.org/wiki/Linked_list

However, Java LinkedList implements List, Queue, Deque, and more. http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html

You cannot find a method on LinkedList that gives you the next or previous object in the list, the best you can do is get an Iterator and get the objects. My question is why Java named this LinkedList data structure, although it is not a truly linked list? A linked list can be implemented in Java as follows:

Public class MyLinkedList{
 public int value;
 public MyLinkedList next;
}
+6
source share
7 answers

My question is why Java named this LinkedList data structure, although this is not a really linked list?

Because its implementation is a linked list. From the documentation :

Compatible with double list of interfaces Listand Deque. Performs all optional operations with lists and resolves all elements (including null).

LinkedList- this Listis implemented through a linked list ArrayList- this Listis implemented using an array, etc. Which of the options you have chosen may matter in terms of runtime characteristics. For example, from LinkedListdocs:

, . , , , , .

, , , next Iterator, Iterator listIterator, , get .

+5

LinkedList,

, . " " . node , , Java API. , - . , . , / .

, , "node" "list", , , .

, , ? , , , API - .

+5

, . LinkedList java.util.List .

, API, /, .

, LinkedList node, :

 957       Node < E> {
958 E;
959 Node < E > next;
960 Node < E> prev;
962 Node ( Node < E> prev, E, Node < E> next) {
963 this.item = element;
964 this.next = next;
965 this.prev = prev;
966}
967} < /">
+3

, , . .

, , Big-O List.

+1

Java LinkedList List, Queue, Deque .

API, LinkedList , .

0

, , .

, , . , , LinkedList, API-, .

, , O(1) , O(1) , O(n) .., , .

LinkedList next , . Java, .

Java - , Abstraction.

0

, @Marko , , 1.8 jdk, .

, :

 transient int size = 0;

This value increases each time a node is added to the list. This means that the list has an internal node restriction Integer.MAX_VALUE (2147483647). In the modern world, this number is not as large as it seems. The problem is not that we don’t have a real linked list (it’s trivial to create one), but with all third-party libraries they most likely will not take this into account, and then the whole library will be abandoned,

0
source

All Articles