在Android在Java中如何创建一个Multimap之创建一个、Android、Java、Multimap

2023-09-06 15:41:21 作者:草根

我在哪里可以找到multimap中的Java,将工作在Android上的一种实现,而不包括任何其他类等我发现都需要需要其他的东西其他东西的实现,它就会变得混乱很快。我从C移植项目++和是新来的Java(而这个项目也让我试图让事情尽可能相同,而得到它的工作),所以任何参考或例子将是巨大的。

Where can I find an implementation of multimap for Java that will work on Android without having to include any other classes etc. The implementations I've found all require other things which require other things and it gets messy quick. I'm porting a project from C++ and am new to java (and this project as well so I'm trying to keep things as identical as possible while getting it working) so any references or examples would be great.

推荐答案

您可以使用地图和列表来创建一个多重映射。假设你想一个整数,类类型T的列表关联使用下列code:

You could use a Map and a List to create a multimap. Say you wanted to associate an integer with a list of class type T. Use the following code:

地图<整数,列表< T>> myMultiMap =新的HashMap<整数,列表< T>>();

这可能会导致混乱,但是,这应该给你你要寻找的。

It could get messy but, this should give you what you're looking for.

另一种方法是使用番石榴库的Multimap实现。

Another option is to use the Guava library's Multimap implementations.