I need to remove the duplicates in this array:
int[] array = {20, 100, 10, 80, 70, 1, 0, -1, 2, 10, 15, 300, 7,
6, 2, 18, 19, 21, 9, 0};
Using a custom method.
how do I go about this?
I need to remove the duplicates in this array:
int[] array = {20, 100, 10, 80, 70, 1, 0, -1, 2, 10, 15, 300, 7,
6, 2, 18, 19, 21, 9, 0};
Using a custom method.
how do I go about this?
Use a HashSet
You can try this:
Set<T> mySet = new HashSet<T>(Arrays.asList(someArray));
Set stores only unique elements.
Convert back your set to array using myset.toArray()