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
  • 91,013
  • 29
  • 181
  • 233

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
  • 3,855
  • 1
  • 15
  • 24