0

I am new to Java, With respect to this question remove same values from an array How can we achieve it using java. Any help would be greatly appreciated?

2
  • Arrays are a bad choice for that. Use ArrayList instead. Commented Aug 14, 2015 at 11:16
  • Actually a HashSet would be the way to go for a list of Strings. Though nallar is right. This has been answered before. Commented Aug 14, 2015 at 11:18

3 Answers 3

2

You could use a Set (e.g. HashSet), or a Map (e.g. HashMap). For each value in the array, just place it in the Set (or as a key in the Map).

You will then have a collection without duplicates (you can transform it back to an array if you need).

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

Comments

0

You can achieve this simply by using the collections.

use set or HashMap and put the elements in the collections. when you retrieve you will get the unique elements .

If you are looking for pattern matching... better for the RegEx.

Comments

0

Actually, you should use HashSet, it will remove duplicate values.

For sorting, you should use TreeSet.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.