This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Obsolete collection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Obsolete collection?" Watch "Obsolete collection?" New topic
Author

Obsolete collection?

Charles Mulloy
Ranch Hand

Joined: Oct 25, 2009
Posts: 30
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?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
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.
Charles Mulloy
Ranch Hand

Joined: Oct 25, 2009
Posts: 30
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?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60807
    
  65

If you are not accessing the list from multiple threads, it's nothing to worry about.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Obsolete collection?
 
Similar Threads
Button Action using netbeans
Convert working program to display in GUI
Is Vector an obsolete collection class?
returning String from ActionPerformed
JPanel Form Problems