I need to separate and count how many values in arraylist are the same and print them according to the number of occurrences.
I\'ve got an arraylist called digits :<
Java 8 can handle this problem with 3 lines of code.
Map duplicatedCount = new LinkedHashMap<>(); list.forEach(a -> duplicatedCount.put(a, duplicatedCount.getOrDefault(a, 0) +1)); duplicatedCount.forEach((k,v) -> System.out.println(v+" times "+k));