java.util.Vector
Previously I would always have thought a Vector was good to use for non-descript objects when length was unknown. As far as I was aware I thought it was thread-safe too
What would change that Vector
shouldn't be used anymore, and what is the alternative?
You should use ArrayList
instead of Vector
. Vector
used internal synchronisation, but that is rarely good enough for actual consistency, and only slows down execution when it is not really needed.
Also see this stackoverflow question.
You can use an ArrayList
instead.
If you need a synchronized version, you can do something like:
ArrayList arrayList = new ArrayList();
List synchList = Collections.synchronizedList(arrayList);
ArrayList
is now the better class to use. Vector
is now considered Legacy, and has the added performance overhead of being Thread-Safe.
下一篇: java.util.Vector中