这是在少数情况下,用代码显示比用普通英语解释更容易的情况之一:
int targetIndex = 0;for( int sourceIndex = 0; sourceIndex < array.length; sourceIndex++ ){ if( array[sourceIndex] != 0 ) array[targetIndex++] = array[sourceIndex];}int[] newArray = new int[targetIndex];System.arraycopy( array, 0, newArray, 0, targetIndex );return newArray;


