Tuesday, November 29, 2011

Diff between ArrayList and Vector?

Vector class is Synchronized and ArrayList class is not Synchornized.:Vector is Synchronized ie we can change the size of that array But Array list is not synchronized ie once we declare the size of the array we can,t change during run time..:Array contains simillar type of objects.but vector is capable of haing different type of objects.:1.Arraylist is not synchronized while vector is.:Vectors are synchronized and also legacy classes. for thread safety purpose all the methods of the vector are synchronized so it gives us performance hit while in case of ArrayList none of the methods are synchronized and the big advantage is ArrayList is a growable array of objects and it gives faster faster iteration and fast random access. Better choice is ArrayList. :1. Vector is synchronized where as array list is not synchronized, If you want to synchronize array list we have to use Collections.synchornizeList() method.:1) Arraylist is not synchronized while vector is. :sorting and searching is possible in array list which is not possible in vector:An ArrayList is ordered collection (also known as a sequence). It means that the user of controls where each element is inserted. This class is very similar to the Vector class, excepting that it is not synchronized. It must be synchronized externally.:ArrayList is a variable length array of object references.ie. It can dynamically increase or decrease in size.:Vector is synchronized where as ArrayList is not synchronized.:ArrayList:- When the size is fulled then it increses the half of the size.:vector - default size as 10
Category:Java Interview Questions

No comments:

Post a Comment