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).
Did you try Functional Java? Also there's similar question, you could use that algorithm and make singly list from double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With