Do you need the synchronization afforded by the Vector
class? If not, then you don't want to use the Vector
class. (If only JList
allowed using an ArrayList
in its place.) The cost of uncontended synchronization is way lower in recent JVM versions, way lower than it used to be. Still, there's no reason to use unnecessary synchronization.
It looks like Kathy Van Stone may be referring to that extra synchronization in Vector
.
Note carefully the JavaDoc for public JList(Vector<?> listData)
:
The created model references the given Vector directly. Attempts to modify the
Vector after constructing the list results in undefined behavior.
Unfortunately, the JavaDoc for public JList(Object[] listData)
has the same warning:
The created model references the given array directly. Attempts to modify the
array after constructing the list results in undefined behavior.
You have to decide if there is any likelihood that someone decides that the Vector
is useful later in the same method and thus modifies the code like this:
Vector vec = new Vector<String>(LinkedHashMap.keySet());
jList1.setListData(vec);
// Other stuff with Vector
vec.add( .... ); // Adding some data type that fits in the Vector
... or of course the same change with the Array constructor version.