Reputation: 9289
Coming from functional background, I am looking for equivalent of immutable singly linked list in Java.
Immutable singly linked lists give me freedom to define many lists with common tail. For example, if I have list = [1,2,3]
and then I am creating two new lists:
first = [10 | list]
second = [15 | list]
I am not copying the list. Internally it looks more like this:
first -> 10 -> 1 -> 2 -> 3 -> null
second -> 15 /|\
I looked at Guava Lists, but I couldn't find information on implementation details. As far as I understand, it is a doubly linked list, so efficient prepend operation is impossible (please correct me, if I am wrong about that).
Upvotes: 3
Views: 3268
Reputation: 1964
Try Vavr it's open source so you can see the internal implementation.
Upvotes: 1
Reputation: 829
Did you try Functional Java? Also there's similar question, you could use that algorithm and make singly list from double.
Upvotes: 3