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
- Java Collections Interview
- List Interface In Java
- ArrayList
- LinkedList
- Custom Own ArrayList Implementation
- Custom LinkedList implementation in java
- Set Interface In Java
- Map Interface In Java
- HashMap
- TreeMap
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment