Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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));
        }
    }
}
 
PREVIOUS NEXT
Tagged: #frequency #element #list #java
ADD COMMENT
Topic
Name
9+3 =