Java Arraylist VS Vector in context of threading
Java ArrayList VS Vector
ArrayList properties
ArrayList is
implemented using array as internal data structure. It can be dynamically
resized
ArrayList increases half of its
size when its size is increased
ArrayList faster than Vector
Vector properties
Vector is synchronized (so thread safe)
Vector is implemented using array as internal data structure.
It can be dynamically resized.
Vector doubles size of array when its size is increased.
Major difference between ArrayList and Vector is that ArrayList
is not synchronized and Vector is synchronized. That is why vector can be used
in multi threaded and concurrent environment more appropriately and
efficiently. We can use ArrayList in multi threading environment if multiple
threads are only reading values from ArrayList. We can also make read only
ArrayList as well. ArrayList faster than Vector as it is Asynchronous. so if we want to read only ArrayList is more efficeint and faster than Vector.
In my point of view normally we have to use ArrayList because it offers better performance.
ReplyDeleteBut
Vector has just one advantage that is its a synchronized for concurrent modification. But it turns out that this feature isn't very useful. if you are writing concurrent code, you typically need to lock at a much higher level of granularity than an individual collection class.
In context of multi threading vector works more efficiently and safe for both read and writing operations. if you want to do only read operation then Arraylist is best. Arraylist is efficient in term of memory management and speed
ReplyDelete