Java List get element frequency

Description

Java List get element frequency


import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Integer> values = Arrays.asList( 5, 0, 0, 2 );
        int occurrences = Collections.frequency(values, 0);
        System.out.println("occurrences of zero is " + occurrences);
        /* w w w  .j  av  a 2s.  co  m*/
        occurrences = Collections.frequency(values, 5);
        System.out.println("occurrences of 5 is " + occurrences);
    }
}



PreviousNext

Related