Answers for "how to count frequency of elements in array in java"

0

frequency of each element from list in java

public static void main(String[] args)
    {
        List<String> list = Arrays.asList("B", "A", "A", "C", "B", "A");

        Set<String> distinct = new HashSet<>(list);
        for (String s: distinct) {
            System.out.println(s + ": " + Collections.frequency(list, s));
        }
    }
}
Posted by: Guest on October-04-2021

Code answers related to "how to count frequency of elements in array in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language