java 我如何为java导入multimap?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14925329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:52:50  来源:igfitidea点击:

how do i import multimap for java?

javamapmultimap

提问by Matt M

This is kind of stupid but how do I install MultiMap?

这有点愚蠢,但我如何安装MultiMap

I need a way to store multiple values to keys and my map implementation isn't working

我需要一种将多个值存储到键的方法,但我的地图实现不起作用

回答by 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 Multimapimplementation (which I would recommend) is available in Guava, Google's utility library.

该类MultiMap不是 Java 标准库的一部分。它是Apache Commons 的一部分,这是许多 Java 开发人员发现有用的一组单独的实用程序类。Google 的实用程序库Guava 中Multimap提供了另一种实现(我会推荐)。

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

无论哪种情况,为了使用这些类,您都需要下载项目分发的 jar,并在运行程序时将其添加到类路径中。您可以在命令行执行此操作:在命令行(javac 或 apt)或 Eclipse中的类路径中包含 jar将 JAR 添加到 Eclipse Java 库

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.

如果您在 Google 上搜索诸如“安装 jars”和“将 jars 添加到 eclipse”之类的词组,如果您仍在苦苦挣扎,您会发现许多资源可以帮助您。

回答by Cratylus

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 collectionsto your classpath. Download the jar and include it in your classpath.

multimap 类似于 Map,但它可以将每个键映射到多个值。如果您自己的不起作用,您可以将apache commons 集合添加到您的类路径中。下载 jar 并将其包含在您的类路径中。

But you could also implement your own multimap as: HashMap<SomeObject, List<YourObject>>()
Check example here under multimaps

但您也可以将自己的多映射实现为:HashMap<SomeObject, List<YourObject>>()
在多映射下查看示例

回答by Inversus

It's not the MultiMap class, but I code around this issue by using a collection as the value thusly:

它不是 MultiMap 类,但我通过使用集合作为值来解决这个问题:

HashMap<String, ArrayList<Integer>> metrics = new HashMap<String, ArrayList<Integer>>();

回答by rakeeee

Maven dependency for multimap utility

多图实用程序的 Maven 依赖项

 <dependency>
    <groupId>org.solovyev</groupId>
    <artifactId>common-collections-multimap</artifactId>
    <version>1.0.3</version>
</dependency>