what is the diff b/w vector and arraylist?
which one is preferable to use?any new adv of the above?
Printable View
what is the diff b/w vector and arraylist?
which one is preferable to use?any new adv of the above?
[QUOTE=balumanickamM.tech;11936]what is the diff b/w vector and arraylist?
which one is preferable to use?any new adv of the above?[/QUOTE]
1.Arraylist is not synchronized while vector is.
2. Arraylist has no default size while vector has a default size of 10.
3. Arraylist don't define any increment size while vector does.
Methods in Vector are synchronised which means they are thread-safe and thus preclude access to the Vector elements by concurrent threads.But this imposes additional overhead on the JVM as it has to acquire and release locks on the vector objects under consideration.
This is not possible in ArrayList since those methods are not synchronised and hence are faster in performance.
Use Vector only if it will be accessed by multiple threads at a time else ArrayList is always better.
which is Better?
Depends on the requirement only we can able to choose the either Vector / ArrayList
Differences :
--------------
1.Synchrnonization:
-------------------
Vector is Synchronised.ArrayList is Unsynchronised
2.Data Growth:
----------------
Both Vector and ArrayList are Dynamic arrays.
Vector : doubling the size of its array
ArrayList : 50% increase its array size
3.Element Addition & Removal:
-------------------------------
Both Vector & ArrayList are good for adding & removing the element at the end.But if it comes to other positions boh are cost effective.So that time we have to search for better container like LinkedList.
dear all,
i am new member of this forum.
thanks
pulak