• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Obsolete collection?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not accessing the list from multiple threads, it's nothing to worry about.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic