我有一个包含一些数字的嵌套 ArrayList。
ArrayList<Integer[]> list = new ArrayList<Integer[]>();
list.add(new Integer[] { 1, 2, 3, 4 });
list.add(new Integer[] { 1, 2, 4 });
list.add(new Integer[] { 1, 2 });
如何获得它们的频率?
与:
System.out.println(Collections.frequency(list , 1));
我只得到 0
而不是 3
(就我而言)。
最佳答案
试试这个:
int count = 0;
for (Integer[] i: list) {
count += Collections.frequency(Arrays.asList(i), 1);
}
System.out.println(count); //3
关于java - 获取嵌套ArrayList的频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33259193/