Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> LinkedHashSet<T> asLinkedHashSetRemoveNulls(T[] elements) { LinkedHashSet<T> result = new LinkedHashSet<>(elements.length); for (T element : elements) { if (element != null) { result.add(element); } } return result; } }