marcus said:
" Note that this implementation is not synchronized. If multiple threads
access an ArrayList instance concurrently, and at least one of the
threads modifies the list structurally, it must be synchronized
externally."
try vector instead, it is syncronized
Vector is synchronized, but synchronization is not really the problem.
A fail-fast iterator, such as all provided by the standard Collections,
throws ConcurrentModificationException if a method is invoked on it when
the underlying collection has been modified since the Iterator's
creation (by means other than the Iterator itself). That does not
require multiple threads to accomplish, and Vector's synchronization is
in any case too narrow in scope to protect instances from this issue in
a multi-threaded scenario.
The _only_ reason to ever use the Vector class is if you need to
interface with an external API that requires it. Otherwise use
ArrayList instead. For multi-threaded programming you generally need to
provide the same degree of external synchronization for a Vector as you
do for an ArrayList, but with ArrayList you don't run into extra
synchronization barriers. If you think you want a List with per-method
synchronization (like Vector has), then you can run any List you want
through Collections.synchronizedList(List) to get one.