frequency of each element from list in java

Solutions on MaxInterview for frequency of each element from list in java by the best coders in the world

showing results for - "frequency of each element from list in java"
Lara
01 Sep 2020
1    public static void main(String[] args)
2    {
3        List<String> list = Arrays.asList("B", "A", "A", "C", "B", "A");
4
5        Set<String> distinct = new HashSet<>(list);
6        for (String s: distinct) {
7            System.out.println(s + ": " + Collections.frequency(list, s));
8        }
9    }
10}
11