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?

3
  • Have you preserve order? Commented Dec 18, 2016 at 16:39
  • 5
    One approach is by writing code. Commented Dec 18, 2016 at 16:40
  • "Using a custom method" As opposed to what? Do you know of a standard method doing that? Commented Dec 18, 2016 at 17:02

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

... and convert it back to a list.
yea I forgot. Done!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.