【发布时间】:2016-10-18 19:06:17
【问题描述】:
我有一个关于在 java 中将 2d arraylist 转换为 hashmap 的小问题。读取为 2d arraylist 后,我的数据集如下所示:
0 1
0 2
1 2
1 3
第一列代表id,第二列代表item。我想在java中使用hashmap创建频繁项集,输出应该是这样的
1 0
2 0 1
3 1
我使用这些代码,但我遇到了一些问题:
HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
for(Integer elem : data){
map.put(elem[1], elem[0]);
}
data 是我的二维数组列表。
错误信息说
incompatible types: ArrayList<Integer> cannot be converted to Integer
for(Integer elem : data){
^
任何帮助将不胜感激!
【问题讨论】: