public static int[] getNewArray(int[] array) { int[] temp = new int[array.length]; int t = 0; for(int i=0;i<array.length;i++) { boolean flag = true; for(int j=0;j<i;j++) { if(i==0) { continue; }else if(array[i]==temp[j]) { flag = false; break; } } if(flag) { temp[t++] = array[i]; } } int[] newArray = new int[t]; System.arraycopy(temp, 0, newArray, 0, t); return newArray; }
运行结果: