0

我想使用地图有多重价值

前任)

HashMap<String, ArrayList<String>> 

但这似乎太糟糕了

可能是jdk有map,这个作用?

谢谢,请阅读这个问题

4

2 回答 2

1

以您所做的方式定义多映射是完全有效的。JDK 不提供称为 multimap 的集合。尽管 apache commons 已经定义了一个MultiMap接口,其中包含MultiHashMapMultiValueMap等实现类。

如果您不想使用 apache commons MultiMap,那么这里是帮助您了解如何使用 java HashMap 创建自己的 multimap 的教程:

http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html

于 2013-09-12T01:20:53.567 回答
0

试试地图

Map<String, ArrayList<String>> sampleMap = new HashMap<String, ArrayList<String>>();

        ArrayList<String> sampleList = new ArrayList<String>();
        sampleList.add("Value1");
        sampleList.add("Value2");
        sampleList.add("Value3");

        sampleMap.put("Key1", sampleList);
        sampleMap.put("Key2", sampleList);
        sampleMap.put("Key3", sampleList);

        System.out.println("SampleMap : "+sampleMap);
于 2013-09-12T01:21:06.373 回答