B
bob smith
I read that the Vector class is obsolete.
Can someone tell me in a nutshell why this is so?
Thank you.
Can someone tell me in a nutshell why this is so?
Thank you.
I read that the Vector class is obsolete.
Can someone tell me in a nutshell why this is so?
I read that the Vector class is obsolete.
Can someone tell me in a nutshell why this is so?
Same as with Hashtable.
It's all synchronized, = slow.
And to make things worse, returned iterators are not synchronized![]()
I read that the Vector class is obsolete.
Can someone tell me in a nutshell why this is so?
Thank you.
Mostly mythology. The Vector provides some additional functionality
over a synchronized List but it's probably not something you will need.
If you don't need any synchronization then use an ArrayList, if you do
the Vector will work fine too.
I use Vector every time I can just to send the big giant heads into a
tizzy.
Same as with Hashtable.
It's all synchronized, = slow.
And to make things worse, returned iterators are not synchronized![]()
Also, there are a few API's in the core Java suite that still deal
in Vectors, particularly in Swing: DefaultComboBoxModel, JList, JTree,
DefaultTableModel, ...
Eric Sosman said:I'm "mostly" in agreement. For curiosity's sake, though, I ran
a few simple timing tests and found that Vector took about 35% more
time than ArrayList (for the mix of operations I tried).
"That's HU-U-U-GE!" somebody's shouting, but does it truly make a
difference? What else is the program doing, and how much time does it
spend on things other than List manipulation? Like, say, constructing
Well, even when the program is spending more time in other tasks, why
use a slow class when you can easily replace it with a faster one that
does the same thing?
And about the synchronization: in many cases, when you need
synchronization, you will need to synchronize something more than just
the Collection manipulation. And if the Collection handling is already
within a synchronized block, why use one more synchronization block
inside another one?
On 5/30/2014 5:30 PM, Jukka Lahtinen wrote:
In a multi-threaded setting you need to pay close attention to
exactly which manipulations need to be atomic. Vector or the Lists
produced by Collections.synchronizedList() will guarantee atomicity
for the individual method calls, but (as has been pointed out a few
times already) the program may require some combinations of those to
be atomic. The classic example is iterating over the collection:
Just because .add() and .remove() and so on (and the Iterator methods
themselves) are atomic doesn't imply that the entire iteration is so.
Finally, I question the wisdom of a program design that requires
iterating over a collection shared by multiple threads.
I read that the Vector class is obsolete.
Can someone tell me in a nutshell why this is so?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.