Wednesday, March 27, 2013

Difference between ArrayList and Vector

Difference between ArrayList and Vector                   
                                 ArrayList ,Vector are mot important classes in Java Collections.The most important core java question is Difference between ArrayList and Vector.

1. In Vector, every method is synchronized and thread-safe. But ArrayList doesn't contain synchronized methods and it is not a thread-safe.

                        By default ArrayList is non-synchronized but we can get synchronized version of ArrayList object by using synchronizedList() method of Collections class.

2. Vector the threshold limit, it increase itself by value specified in  capacityIncrement field while you can increase size of ArrayListby calling ensureCapacity() method. 

3.Vector can return enumeration of items it hold by calling elements() method.ArrayList can return listIterator of items it hold by calling listIterator().

4.ArrayList performance is High and Vector performance is low.

5.Vector is introduced in  1.0 version and ArrayList is introduced in 1.2 version.b

6. ArrayList object with default initial capacity is 10 if reaches its capacity a new ArrayList Object is created with 
                           newcapacity=(Currentcapacity*3/2)+1

                Vector object  with default initial capacity is 10 if reaches its capacity then a new Object will be created with 
                      newcapacity= Currentcapacity*2

No comments:

Post a Comment