On Aug 24, 8:51 am, Patricia Shanahan <p...@acm.org> wrote:
What is the purpose of the list.contains(obj) pre-check?
My bad..did not realize contains returns a boolean. Been thinking
about this for a while, and I was wondering if it makes sense to use
an array (or another list..a clone) as an intermediatory. I know this
has scalability and performance numbers against it though. Here is a
little snippet:
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0; i<10; i++){
list.add(i);
}
//remove all the even numbers
Integer[] array = new Integer[list.size()];
list.toArray(array);
for( int i:array ){
if( i%2==0 ) {
list.remove(new Integer(i));
}
}
System.out.println(list);
Ofcourse this needs to be synchronized, to make sure the array and the
list do not go out of sync.
-cheers,
Manish