Let's say I have the following Map
which is created using Guava's library: (List<Integer>
is also immutable)
Map<String, List<Integer>> map = ImmutableMap.builder()...
I pass this map to a class where I want to create a mutable copy of it and modify it. It is of course possible to do it manually, but is there a way to convert a nested immutable collection back to a mutable one?
As pointed out, I'd use an ImmutableListMultimap<String, Integer>
instead of a ImmutableMap<String, ImmutableList<Integer>>
.
Then if you want a mutable copy, you can just pass the immutable multimap to the create
static factory method on one of the mutable ListMultimap
implementations (ArrayListMultimap
or LinkedListMultimap
).
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