Javatpoint Logo
Javatpoint Logo

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

Test it Now

Output:

10 20 30 40 50 

2) Remove Duplicate Element in Array using separate index

Test it Now

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.

Test it Now

Output:

10 20 30 40 50 70 90 
Next TopicJava Programs


Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA