In Python, the defaultdict
class provides a convenient way to create a mapping from key -> [list of values]
, in the following example,
I wrote the library Guavaberry containing such data structure: DefaultHashMap.
It is highly tested and documented. You can find it and integrate it pretty easily via Maven Central.
The main advatage is that it uses lambda to define the factory method. So, you can add an arbitrarly defined instance of a class (instead of relying on the existence of the default constructor):
DefaultHashMap<Integer, List<String>> map = new DefaultHashMap(() -> new ArrayList<>());
map.get(11).add("first");
I hope that can be of help.
You can use MultiMap from Apache Commons.