Android examples for java.util:Collection and Null
add Not Null Elements to Collection
//package com.book2s; import java.util.Collection; public class Main { public static void main(String[] argv) { Collection c = java.util.Arrays.asList("asdf", "book2s.com"); Collection es = java.util.Arrays.asList("asdf", "book2s.com"); System.out.println(addNotNullElements(c, es)); }/* w ww. ja v a 2s. co m*/ public static <E> boolean addNotNullElements(Collection<E> c, Collection<E> es) { if (!isNotNull(c)) { return false; } if (!isNotNull(es)) { return false; } c.addAll(es); return true; } public static boolean isNotNull(Collection<?> c) { if (c == null || c.isEmpty()) { return false; } else { return true; } } }