Fastest ArrayList()

hi, i've got a problem. i want to remove all replaying object from the arraylist. in my list a i have 13,000 object, and after removing i should have about 40 elements in my list. how can i do this in simpliest way. thanks for any advice, best regards. Alcatraz
[269 byte] By [alcatraz123a] at [2007-11-27 7:30:52]
# 1
Create a new ArrayList and copy over only those items you need from the old to the new.
sabre150a at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 2
Don't use an ArrayList, use a LinkedList. If you need an ArrayList for other reasons it would be far quicker to convert it to a LInkedList, do the deletions on the LinkedList, then convert back to an ArrayList, than to do 12960 deletions on an ArrayList.
ejpa at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 3
> i want to remove all replaying object from the arraylist. What does replaying mean? Duplicates?
thomas.behra at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 4

Do you want simple or fast? This is simple:

List removeDups(List aList) {

return new ArrayList( new HashSet( aList ) );

}

Assuming "replaying" means duplicates

Mr.E.H.a at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 5

> Do you want simple or fast? This is simple:

> [code]

> List removeDups(List aList) {

>return new ArrayList( new HashSet( aList ) );

> code]

> Assuming "replaying" means duplicates

Odds are this will be more than fast enough anyway. Don't go looking for anything more exotic unless you measure and determine for sure that this is an unacceptable bottleneck.

Also, make sure you override equals and hashCode properly.

http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf

jverda at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 6
And can you work with a Set instead of a List from the beginning, to avoid duplicates altogether?And where is this data coming from? A database? select DISTINCT?
Hippolytea at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...
# 7

You may want to use a LinkedHashSet rather then a HashSet i you wish to maintain order in the approach given above.

But you are probably better off using a TreeSet rather then a list if order is important. (rather then oing though the conversion just don't put duplicates in the data structure in the first place)

matfud

matfuda at 2007-7-12 19:11:08 > top of Java-index,Java Essentials,Java Programming...