数组去除空值,并组成新的数组
public static <T> T[] arrayToRemoveNullData(T[] array) { List<T> list = new ArrayList<T>(); for (int i = 0; i < array.length; i++) { if (array[i] != null) { list.add(array[i]); } } @SuppressWarnings("unchecked") T[] newArray = (T[])Array.newInstance(array.getClass().getComponentType(), list.size()); return list.toArray(newArray); }