+ 2
Can anyone explain proper difference between arraylist and vector?
3 Respostas
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.
0
What does it mean to be synchronised here?
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