• 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

java.util Decisions

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey All:
Okay, I'm going over everything and I'm having a tough time justifying all of my decisions as far as which type of collection I used under different circumstances. There are some few times when I used a certain one for a certain purpose, but more often than not there was not a compelling reason to use one over the other, so I just used Vector generally (because I'm most familiar with it). There are several places where it seems you could use
most any collection. For instance, my lockHolder. I made it a Vector, but there's not a particularly compelling reason why. I mean, it works! It seems like it would have worked equally well, with most any other collection. Any profound insights on this one?
With Respect,
matt
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java in a Nutshell: "Vector is quite similar to the ArrayList class, except that the methods of Vector are synchronized, which makes them thread-safe but increases the overhead of calling them. If you need thread safety or need to be compatible with Java 1.0 or Java 1.1 use Vector, otherwise use ArrayList."
It says the same for Hashtable vs. HashMap.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another option would be to use one of the Collections.synchronizedXxx() methods to synchronize your collection.
 
Doug Melzer
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you do use the Collections framework, then deciding upon required behaviors will help you to decide whether to use a Set, List, Map, etc.
For example, are duplicate entries allowed, do you want to look up an object based upon some sort of key (perhaps a record #), etc.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding the synchronization: Keep in mind that you only need synchronized collections if concurrent modification can occur to the collection. If you do your synchronization within your methods and no concurrent modifications can happen, use the unsynch'ed ones.
Rainer
 
reply
    Bookmark Topic Watch Topic
  • New Topic