*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes java.util Decisions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "java.util Decisions" Watch "java.util Decisions" New topic
Author

java.util Decisions

Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
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
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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.
Doug Melzer
Ranch Hand

Joined: Mar 23, 2000
Posts: 51
Another option would be to use one of the Collections.synchronizedXxx() methods to synchronize your collection.
Doug Melzer
Ranch Hand

Joined: Mar 23, 2000
Posts: 51
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.
R Bischof
Ranch Hand

Joined: Feb 13, 2001
Posts: 48
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


Rainer<br />SCJP, SCJD, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util Decisions