This is kind of stupid but how do I install MultiMap?
I need a way to store multiple values to keys and my map implementation isn't working
That class, MultiMap
, is not part of the Java standard library. It is part of Apache Commons, a separate set of utility classes many Java developers find useful. An alternate Multimap
implementation (which I would recommend) is available in Guava, Google's utility library.
In either case, in order to use these classes, you need to download the jar distributed by the project, and add it to your classpath when you run your program. You can do this at the command line: Including jars in classpath on commandline (javac or apt) or in Eclipse: Adding a JAR to an Eclipse Java library
If you Google for phrases like "installing jars" and "adding jars to eclipse" you'll find many resources to help you if you're still struggling.
A multimap is like a Map but it can map each key to multiple values. If your own does not work you can add apache commons collections to your classpath. Download the jar and include it in your classpath.
But you could also implement your own multimap as: HashMap<SomeObject, List<YourObject>>()
Check example here under multimaps
It's not the MultiMap class, but I code around this issue by using a collection as the value thusly:
HashMap<String, ArrayList<Integer>> metrics = new HashMap<String, ArrayList<Integer>>();
Maven dependency for multimap utility
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>common-collections-multimap</artifactId>
<version>1.0.3</version>
</dependency>