number of occurance of all elements in an array code example
Example 1: javascript Count the frequency of a value in an array
const countOccurrences = arr => arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {});
countOccurrences([2, 1, 3, 3, 2, 3]);
countOccurrences(['a', 'b', 'a', 'c', 'a', 'b']);
Example 2: get ocurrences in array java
List asList = Arrays.asList(array);
Set<String> mySet = new HashSet<String>(asList);
for(String s: mySet){
System.out.println(s + " " +Collections.frequency(asList,s));
}