+ 2

Can anyone explain proper difference between arraylist and vector?

5th Jul 2016, 12:37 PM
Shipra Chordia
Shipra Chordia - avatar
3 ответов
0
Vector is a thing of the past. The main difference is that its methods are synchronized, whereas those in ArrayList are not. If you want a synchronized object, use Collections.synchronizedCollections as a better alternative to Vector.
5th Jul 2016, 1:16 PM
Aliénor Latour
Aliénor Latour - avatar
0
What does it mean to be synchronised here?
5th Jul 2016, 1:35 PM
Shipra Chordia
Shipra Chordia - avatar
0
First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object. Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads. See https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
5th Jul 2016, 1:39 PM
Aliénor Latour
Aliénor Latour - avatar