Folks - I've encountered a problem with Java 1.6 ver 13 but can't find the bug reports to see if a) it's been reported or b) if it is fixed in a later version. The problem is that ArrayList is removing the wrong object. If an array contains a set of strings, some of which are duplicate strings but different objects, the removal of an object where the string is duplicated removes the
first occurance of the string not the object.
Any help or pointers are appreciated. Especially a pointer to the bug reports for Java so I can do a search and/or submittal.
Lori <*>
The following code produces this output:
--- After initialization ---
Index 0 is Test
Index 1 is Foo
Index 2 is bar
Index 3 is Test
--- After removal ---
Index 0 is Foo
Index 1 is bar
Index 2 is Test
import java.util.ArrayList;
public class ArrayListTest extends Object {
public static void main(String[] args) {
final String TEST = "Test";
final ArrayList<Object> list = new ArrayList<Object>();
list.add(new String(TEST));
list.add("Foo");
list.add("bar");
final Object remove = new String(TEST);
list.add(remove); System.out.println("--- After initialization ---");
for (int i = 0; i < list.size(); i++) {
System.out.println("Index " + i + " is " + list.get(i));
}
list.remove(remove);
System.out.println("--- After removal ---");
for (int i = 0; i < list.size(); i++) {
System.out.println("Index " + i + " is " + list.get(i));
}
}
}