I need a collection that behaves something like C++ multimap, but I also need to be able to get elements by a range of keys.
+2
A:
There is no built-in multimap collection in Java. To solve this you can map to every key a list of values: Map<String, List<String>>
, for example. Otherwise there are third-party libraries with implemented multimaps - here is one of them.
Petar Minchev
2010-04-17 12:49:38
+4
A:
You can look into Google Collections. It has multiple implementations for MultiMap
.
Matt Dearing
2010-04-17 12:51:53
In particular. the Google Collections TreeMultimap class includes an asMap() method returning a SortedMap. You can then call methods like SortedMap.subMap() to retrieve mappings for a range of keys.
Jared Levy
2010-04-18 07:18:29