This is another possibility. The cost is O(n + m) where m is the max value of the input array.
public static void main(String[] args) {
int arr[] = {23, 56, 78, 92, 44, 3, 3, 3, 23, 11, 10, 10, 10, 10};
// Find the size for the new array to allocate.
int max = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
// Mark the values stored in the array (hit or miss array)
int[] presence = new int[max + 1];
for (int i = 0; i < arr.length; i++) {
presence[arr[i]] = 1;
}
// Find the size for the new array to allocate
int count = 0;
for (int i = 0; i < presence.length; i++) {
if (presence[i] != 0) {
count++;
}
}
// Store the element in the new array when hit
int[] res = new int[count];
int index = 0;
for (int i = 0; i < presence.length; i++) {
if (presence[i] != 0) {
res[index] = i;
index++;
}
}
for (int i = 0; i < res.length; i++) {
System.out.print(res[i] + ", ");
}
}
I know for sure this can improved significantly , but you may use this as a starting point.