I want to remove every duplicate from an array in Java and store the remaining integers in the same array.
E.g.: int[] = { 5,5,5,3,4,4,2,2,1}; ==> int[] = {3,1};
So far I have tried using:
Set<Integer> set = new HashSet<Integer>();
for (int i = 0; i < array.length; i++) {
set.add(array[i]);
}
It appears though, that this only removes one of the duplicates and not both.
Any help would be appreciated.