Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <E> boolean addNotNullElement(Collection<E> c, E e) { if (!isNotNull(c)) { return false; } if (e == null) { return false; } c.add(e); return true; } public static boolean isNotNull(Collection<?> c) { if (c == null || c.isEmpty()) { return false; } else { return true; } } }