1

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?

Maroun
  • 94,125
  • 30
  • 188
  • 241

1 Answers1

1

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()

FallAndLearn
  • 4,035
  • 1
  • 18
  • 24