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 :<
You can count the number of duplicate elements in a list by adding all the elements of the list and storing it in a hashset, once that is done, all you need to know is get the difference in the size of the hashset and the list.
ArrayList al = new ArrayList();
al.add("Santosh");
al.add("Saket");
al.add("Saket");
al.add("Shyam");
al.add("Santosh");
al.add("Shyam");
al.add("Santosh");
al.add("Santosh");
HashSet hs = new HashSet();
hs.addAll(al);
int totalDuplicates =al.size() - hs.size();
System.out.println(totalDuplicates);
Let me know if this needs more clarification