how to find how many times does an object comes in an arraylist code example
Example: how to find how many times does an object comes in an arraylist
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));
}