3

While doing a get() on a MutableListMultimap, the list being returned is made unmodifiable (referring to code in AbstractMutableMultimap#get() ).

What is the thought process behind this ? If the collection being used as value in Multimap is of type MutableList wouldn't it make more sense to keep it that way ?

If not, what is the right way to modify that collection ?

Prateek
  • 417
  • 6
  • 9

1 Answers1

4

The purpose of get() on Multimap (including a MutableListMultimap) is to provide a view of the values associated with the given key, not to modify the values collection.

If you wish to add or remove values associated with a key, you must use put(key, value) or remove(key, value).

  • In that case how are `MutableListMultimap` and `ImmutableListMultimap` different ? Does the Mutable or Immutable property apply to Multimap instead of the collection within ? – Prateek Nov 04 '15 at 11:23
  • 2
    The ImmutableListMultimap doesn't provide methods like put() and remove(). – Bhavana Hindupur Nov 04 '15 at 12:03