Here you can find the source of removeNulls(T[] array)
public static <T> T[] removeNulls(T[] array)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static <T> T[] removeNulls(T[] array) { for (T t : array) { if (t == null) { List<T> list = new ArrayList<>(); for (T t2 : array) if (t2 != null) list.add(t2);//from ww w. ja v a2s . co m return list.toArray(Arrays.copyOf(array, list.size())); } } return array; } /** Add arrays * @param array1 An array to add to (or null) * @param array2 An array to add to (or null) * @return new array with contents of both arrays, or null if both arrays are null * @param <T> the array entry type */ public static <T> T[] add(T[] array1, T[] array2) { if (array1 == null || array1.length == 0) return array2; if (array2 == null || array2.length == 0) return array1; T[] na = Arrays.copyOf(array1, array1.length + array2.length); System.arraycopy(array2, 0, na, array1.length, array2.length); return na; } }