【发布时间】:2017-12-21 06:26:19
【问题描述】:
我很好奇在数组中删除空值的最有效方法是什么。这是我当前的 null(0) 删除方法。
public static int[] removeNull(int[] array){
int j = 0;
for( int i=0; i<array.length; i++ )
{
if (array[i] != 0)
array[j++] = array[i];
}
int [] newArray = new int[j];
System.arraycopy( array, 0, newArray, 0, j );
return newArray;
}
这种方法的性能如何?我期待它是n。
【问题讨论】:
标签: java arrays performance