Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <T> int countNotNull(Collection<T> objects) { return objects.size() - countNull(objects); } public static <T> int countNull(Collection<T> objects) { int count = 0; for (Object o : objects) if (o == null) count++; return count; } }