106
Java Program to remove duplicate element in an Array
We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted, you can sort it by calling Arrays.sort(arr) method.
1) Remove Duplicate Element in Array using Temporary Array
Output:
10 20 30 40 50
2) Remove Duplicate Element in Array using separate index
Output:
10 20 30 40 50
Remove Duplicate Elements in Unsorted Array
If you have unsorted array, you need to sort it first. To do so, use Arrays.sort(arr) method.
Output:
10 20 30 40 50 70 90
Next TopicJava Programs