1.

Why do we need synchronized ArrayList when we have Vectors (which are synchronized) in Java?

Answer»

Following are the reasons why we need SYNCHRONIZED ArrayLists even THOUGH we have Vectors :

  • Vector is SLIGHTLY slower than ArrayList due to the fact that it is synchronized and thread-safe.
  • Vector's functionality is that it synchronizes each individual action. A programmer's preference is to SYNCHRONIZE an entire sequence of actions. Individual operations are less safe and take longer to synchronize.
  • Vectors are considered outdated in Java and have been unofficially deprecated. Vector also synchronizes on a per-operation basis, which is almost never done. Most java programmers PREFER to use ArrayList since they will almost certainly synchronize the arrayList explicitly if they need to do so.


Discussion

No Comment Found