How can eliminate dulicates from Array

How can eliminate duplicates from Array

[46 byte] By [travprasada] at [2007-11-27 11:29:09]
# 1

What is an Array?

If you have a Collection, you can use the Set method addAll() to add them all to a Set. The resulting set will contain no duplicate elements.

If what you have is an array (small 'a'), then add the elements one at a time to a Set to obtain the same result.

pbrockway2a at 2007-7-29 16:26:18 > top of Java-index,Java Essentials,Java Programming...
# 2

The best solution is not to place duplicates in the array in the first place. That is, everytime you try to insert an element, check the array to see if it is already present.

Actually the best solution would be to use a Collection that doesn't allow duplicates such as a Set but I assume you have an assignment that specifies the use of an array.

floundera at 2007-7-29 16:26:18 > top of Java-index,Java Essentials,Java Programming...