Java Collections check value frequency in List
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( 1,2,3,3,2,2,2,1,2,3,2,5, 0, 0, 2 ); int occurrences = Collections.frequency(values, 0); System.out.println("occurrences of zero is " + occurrences); /* w ww .j a va 2s. c om*/ occurrences = Collections.frequency(values, 5); System.out.println("occurrences of 5 is " + occurrences); } }