When I studied linkedlists I have learned that there are 2 different types of them - doubly and singly linkedlists. But when I tried to create a linkedlist in java myself I found out that I can't differentiate them, since there is only one class implementing it "LinkedList". So does java treat all linkedlists as doubly linkedlists or I don't understand something? And if I want to create a singly linklist what should I do? Thanks
Asked
Active
Viewed 68 times
-1
-
The Java `LinkedList` implementation is a doubly-linked list. If you really wanted (for some strange reason) a singly linked list, you'd have to make one yourself (or use a library). But there are not many reasons to [use LinkedList](https://stackoverflow.com/q/322715/2541560), singly or doubly linked. – Kayaman Feb 17 '21 at 22:00
1 Answers
1
If you read the documentation, i.e. the javadoc of LinkedList
, it starts by saying:
Doubly-linked list implementation of the
List
andDeque
interfaces.
There is no singly-linked list implementation in the Java Runtime Library. There is no need for one, since the memory savings are too small to really matter.

Andreas
- 154,647
- 11
- 152
- 247