Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obsolete collection?

 
Charles Mulloy
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not accessing the list from multiple threads, it's nothing to worry about.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17620
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic