how to find how many times does an object comes in an arraylist
List<String> arr = Arrays.asList("a", "a", "b", "a", "a");
Set<String> 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));
}