ArrayList is not thread safe/syncronized
Vector is thread safe/syncronized
ArrayList is faster than Vector
Both allow duplicate values and keep ordering
Both are implementations of List interface
ArrayList is not thread safe
Vector is thread safe/syncronized
ArrayList is faster than Vector
Both allow duplicate values and keep ordering
Both are implementations of List interface
Compare Types of Lists in Java
ArrayList
(extends AbstractList implements RandomAccess, Cloneable, Serializable)
- is dynamic array
- accepts duplicate elements
- is non-synchronized
LinkedList
(extends AbstractSequentialList implements Deque, Cloneable, Serializable)
- is linked list data scructure
- accepts duplicate elements
- is non-synchronized
Vector
(extends AbstractList implements RandomAccess, Cloneable, Serializable)
- growable or dynamic array of objects
- similar to array, but can grow and shrink
- synchronized
- if getting/setting more, use arrayList
--dynamic array perofrms better for get/set
- if adding/removing more, use linkedList
--doubly linked list better for adding removing
- if multi-thread, use Vector over arrayList
--vector's synchronized nature better for multi-thread
- if not multi-threaded, arraylist better
--because it's not synchronized, thus faster