I'm using NetBeans 6.9. My program is using a vector constructed like this:
However, though the program compiles and runs flawlessly, NetBeans is giving me a warning (in the left margin, where the light bulbs show up) and says "Obsolete Collection". It also says that I should surround it with something that looks WAY over my head:
I didn't until recently get this warning. Is there something better I'm supposed to be using or can I just suppress the warning?
In general, Vector is outdated, and you should use ArrayList instead; searching for "java vector arraylist" or some such should find writeups of the reasons for this.
The stuff surrounding it are just comments that you can ignore (and delete); I guess NetBeans uses those for internal purposes.
Joined: Oct 25, 2009
I see. I did a search like you said and found out that arraylists are not thread safe. As far as threads are concerned, the Vector is not used or called outside of a script and even empties once the script completes. Nothing accesses this vector outside this script and chances are there never will be. Should I switch to arrayLists, keep the vectors, or just experiment for a few days?
ArrayLists are not thread-safe, but for this reason operate faster than Vectors. If you need a thread-safe ArrayList, simply create a synchronized list out of it via the Collections.synchronizedList(...) method: Collections API
Vectors are redundant, and you can call them obsolete, but they're not deprecated.
Vectors contain built-in synchronicity support, but these days, you can add synchronized access to any collection. So you can consider Vector as more of a convenience class.
The reason IDE's tend to flag it, is that synchronization requires extra resources, and if you don't need synchronicity, it's more efficient to use a List class. More recently, StringBuffer entered that realm, as StringBuilder is the (long-overdue) non-synchronized equivalent.
An IDE is no substitute for an Intelligent Developer.