how do i import multimap for java?

故事扮演 提交于 2019-12-02 05:15:00
dimo414

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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!