数组去除空值,并组成新的数组
作者:互联网
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); }
标签:getComponentType,getClass,list,空值,newArray,数组,去除,array 来源: https://www.cnblogs.com/lhq1996/p/16446785.html