What is the difference between arraylist and vector classes in collection framework?
Answers
Answer:
ArrayListVector1) ArrayList is not synchronized.Vector is synchronized.2) ArrayList increments 50% of current array size if the number of elements exceeds from its capacity.Vector increments 100% means doubles the array size if the total number of elements exceeds than its capacity.3) ArrayList is not a legacy class. It is introduced in JDK 1.2.Vector is a legacy class.4) ArrayList is fast because it is non-synchronized.Vector is slow because it is synchronized, i.e., in a multithreading environment, it holds the other threads in runnable or non-runnable state until current thread releases the lock of the object.5) ArrayList uses the Iterator interface to traverse the elements.A Vector can use the Iterator interface or Enumeration interface to traverse the elements.
Explanation:
They are dynamically resizable.
- but, ArrayList increases by half of its size when its size is increased. Therefore as per Java API the only main difference is, Vector's methods are synchronized and ArrayLis t's methods are not synchronized.