我有一个ArrayList<ArrayList<String>>
,我想计算一个元素在列表中显示的次数。我也需要关于第3个元素。
[Demo-Site,“”,blah1,09:58:59,2015-08-19]
[hitta,“”,blah4,11:17:14,2015-08-19]
[Demo-Site,“”,blah1,11:26:30,2015-08-19]
[poc-wim,“”,blah2,11:26:54,2015-08-19]
[poc-wim,“”,blah3,11:29:46,2015-08-19]
输出应为:
[Demo-Site,2,blah1,2015-08-19]
[Hitta,1,blah4,2015-08-19]
[poc-wim,1,blah2,2015-08-19]
[poc-wim,1,blah3,2015-08-19]
我知道我可以为数组列表执行此操作,但不太确定如何使用第三个元素执行此操作?
private static void rawReport(ArrayList<ArrayList<String>> data) {
Map<String, Integer> counts = new HashMap<String, Integer>();
for(ArrayList<String> key: data) {
Integer count = counts.get(key.get(0));
if (count == null) {
count = 0;
}
count++;
counts.put(key.get(0), count);
}
for (Entry<String, Integer> entry : counts) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}