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 :<
Well, for that you can try to use Map
Map countMap = new HashMap<>(); for (Integer item: yourArrayList) { if (countMap.containsKey(item)) countMap.put(item, countMap.get(item) + 1); else countMap.put(item, 1); }
After end of forEach loop you will have a filled map with your items against it count