Is Collections.syncronizedList effectively a vector?
Does Collections.syncronizedList(new ArrayList())
effectively makes the arrayList a vector? If no then what extra does it do?
If yes then why was it introduced in the first place?
Thanks.
It provides a synchronized view (a wrapper) of any list. The differences:
- you can make a synchronized view of any list implementation. A synchronized
LinkedList
is not aVector
. - the original list is not synchronized - only the view is.
- It doesn't make a list something else, but wraps a List with something that looks like a list also, but contains no data except the wrapped list.
- See 1.
Collections.synchronizedList(...)
wraps synchronized access to the underlying list, but still retains the underlying list's characteristics in other ways. So for example, if you wrap a LinkedList
, the iterator()
remove()
will be an efficient operation. (The same operation on a Vector
is O(n).)
So the wrapper is absolutely not the same as a Vector
.
精彩评论