Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <T> void addIfNotNullNotExist(Collection<T> col, T val) { if (val != null && !col.contains(val)) { col.add(val); } } public static <T> void addIfNotNullNotExist(Collection<T> col, T[] arr) { if (isEmpty(arr)) { return; } for (T val : arr) { addIfNotNullNotExist(col, val); } } public static <T> boolean isEmpty(T[] vals) { return vals == null || vals.length == 0; } public static <T> boolean isEmpty(T[] vals, boolean checkNullVal) { boolean isEmpty = vals == null || vals.length == 0; if (isEmpty) { return true; } if (checkNullVal) { for (T val : vals) { if (val != null) { return false; } } isEmpty = true; } return isEmpty; } public static boolean isEmpty(Collection<?> col) { return col == null || col.isEmpty(); } }