• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
He's giving us the slip! Quick! Grab this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic