This conversion is written in scala -
(Map of type [K, List[V]]).groupBy(_._1).mapValues(_.unzip._2)
This will return a map with the keys of all different List values and values with a set of corresponding indices for each such group.
When trying to convert this to java -
You can use the Google guava library Multimap
to replace .groupBy (_._ 1), which is -
... a collection that maps keys to values similar to Map, but in which each key can be associated with several values.
But it would be a little difficult to place this for each key, referring to several lists.
How could I accomplish the same task in java HashMap<Key, ListArray<T>>
in java without deconstructing the entire map and listing it manually and rebuilding?
source
share