📌  相关文章
📜  如何查找对象在数组列表中出现的次数 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:46.110000             🧑  作者: Mango

代码示例1
List arr = Arrays.asList("a", "a", "b", "a", "a");

Set printed = new HashSet<>();
for (String s : arr) {
    if (printed.add(s)) // Set.add() also tells if the element was in the Set!
        System.out.println("element: " + s
            + ", count: " + Collections.frequency(arr, s));
}