Originally Posted by
veretimothy
en.verejava.com/?id=19932689743040
package com.tool.util;
public class RemoveDuplicate {
public static void main(String[] args) {
double[] numArray = { 11, 11, 11, 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88, 88 };
double[] newArray = removeDuplicate(numArray);
for (int i=0; i < newArray.length; i++) {
System.out.print(newArray[i]+", ");
}
}
public static double[] removeDuplicate(double[] arr) {
int t = 0;
double[] tempArr = new double[arr.length];
for (int i = 0; i < arr.length; i++) {
boolean isTrue = true;
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) {
isTrue = false;
break;
}
}
if (isTrue) {
tempArr[t] = arr[i];
t++;
}
}
double[] newArr = new double[t];
System.arraycopy(tempArr, 0, newArr, 0, t);
return newArr;
}
}
This works but do you want doubles as a result or integers?
Cheers.