Answers for "how to find the frequency of each element in an arraylist"

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 find the frequency of each element in an arraylist"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language