ArrayList
|
Vector
|
ArrayList & Vector
|
Maintains the insertion order of element
|
Maintains the insertion order of element
|
Both are ordered collection classes as they maintain the
elements insertion order.
|
ArrayList is not Synchronized.
We can make this
Synchronized.
[Collections.synchronizedList(new ArrayList());]
|
Vector is Synchronized.
|
|
ArrayList is not
thread-safe
|
Vector is Thread-safe, shared between multiple
threads.
|
|
Faster than Vector.
Give Better
performance than Vector.
Better for
non-threaded applications.
|
Much Slower than ArryaList for single thread use.
(Synchronization
makes Vector slow)
|
|
|
|
ArrayList and Vector allows null and duplicates.
|
ArrayList is using Iterator for Traversing.
Iterator in the ArrayList is fail-fast iterator.
|
Vector is using both Iterator and Enumerator for
Traversing.
Enumerator in the Vector is not fail-fast.
|
Both Iterator and
ListIterator returned by ArrayList
and Vector are fail_fast
|
ArrayList grow by half of its size when resized.
It increase its array size by 50% while
insertion.
|
Vector doubles the size of its array size.
Vector increments 100% if it exceeds its
capacity.
|
Both use dynamically resizable array as a
data structure internally
They both can grow and
shrink dynamically .(increase or decrease size) when overflow and deletion
happens
|
Doesn’t define increment size.
Default size is 10. (If you create an arraylist means
, you had created array with 10 elements and with values for all as null)
It is better to set initial capacity if you
know the size in advance.
ArrayList<?> list = new ArrayList<>(20);
So
that we can avoid the cost of resizing.(otherwise if it cross size 10,it will
create a new array and copy the data of old to new and , GC the old one)
|
We can set increment size for vector.
public synchronized void setSize(int i)
{}
If you don’t know initial
capacity , but if u know the rate at which array can grow use vector.
|
|
Introduced in java version 1.2(with
collections).
Not a Legacy Class
|
Introduced in first Versions of Java.
As part of Legacy Classes (older version of
java, not used by any one)
|
|
Showing posts with label Difference between arraylist and vector. Show all posts
Showing posts with label Difference between arraylist and vector. Show all posts
Sunday, November 6, 2016
ArrayList vs Vector
Subscribe to:
Posts (Atom)