Jeff Verdegan wrote:
Even in a multithreaded environment, don't use Vector. Use an ArrayList wrapped in a Collections.unmodifiableList(), or something from java.util.concurrent. The only reason to use Vector would be if you have to for interaction with legacy code.
Yes, Verdegan is absolutely right
, you should use ArrayList instead of Vector.You can also use Collections class static method Collections.synchronizedList(List<T> list) which will "Returns a synchronized (thread-safe) list ".
Rob Spoor wrote:And declare it as List, so you can change it later if needed (e.g. wrap it with Collections.unmodifiableList):
In case you are not going to use ArrayList specific methods, it a good idea to declare it as List. So that tomorrow if you feels it is better to have LinkedList instead of ArrayList ( for instance you feel insertion and deletion is more frequent in the middle of the list ), then you just need to replace the ArrayList with LinkedList and rest of the code will remain same.