Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static void checkNoNullElements(Collection<?> collection, String name) { if (collection == null) throw new NullPointerException(name); int index = 0; for (Object element : collection) { if (element == null) throw new NullPointerException(name + "[" + index + "]"); index++; } } }