Thursday, March 31, 2022

ArrayList Vs Vector In Java

ArrayList:

public class ArrayList<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable

All Implemented Interfaces:

Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

Vector:

public class Vector<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable

All Implemented Interfaces:

Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

Similarity for vector and arraylist

  • Vector and ArrayList are resizable-array implementations of the List interface. 
  • Vector and ArrayList both hold object references.
  • Vector and ArrayList both maintain the insertion order of elements, i.e., they are ordered.
  • Vector and ArrayList both internally use an array data structure to store the list.
  • Vector and ArrayList both are members of the Java Collections Framework and implements the List interface.
  • Vector and ArrayList both classes permits null values and duplicates.
  • Iterators returned by the iterator() and listIterator() methods. Vector and ArrayList are fail-fast.
Difference between arraylist and vector

                                ArraList                                 Vector
ArrayList is not a legacy class. It is introduced in     JDK 1.2 Vector is a legacy class.It is introduced in JDK 1.0
ArrayList is not synchronized. Vector is synchronized.
ArrayList is fast because it is non-synchronized. Vector is slow because it is synchronized.
ArrayList can only use the Iterator interface to     traverse the elements Vector can use both Iterator interface and    Enumeration interface to traverse the elements.
ArrayList increments 50% of current array size if     the number of elements exceeds from its     capacity. Vector increments 100% of its initial capacity. if     the total number of elements exceeds than its     capacity.
ArrayList is not thread safe because it is non-        synchronized. Vector is thread safe because it is synchronized.
  The Enumeration returned by the vector method     is not fail-fast.


Related Tutorials 

No comments:

Post a Comment