Java Program to remove duplicate element in an ArrayWe 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 ArrayTest it NowOutput: 10 20 30 40 50 2) Remove Duplicate Element in Array using separate indexTest it NowOutput: 10 20 30 40 50 Remove Duplicate Elements in Unsorted ArrayIf you have unsorted array, you need to sort it first. To do so, use Arrays.sort(arr) method. Test it NowOutput: 10 20 30 40 50 70 90 Next TopicJava Programs |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India