How to choose which Java Colletion Class to use?

How to choose which Java collection class to use?
The Java Collections API provides a whole host of data structures, especially since the API was expanded in Java 5 (and again slightly in Java 6) to include concurrent collections. At first, the array of choices can be a little daunting: should I use a HashMap or a LinkedHashMap? When should I use a list or a HashSet? When should I use a TreeMap rather than a HashMap? But with a bit of guidance, the choice needn't be quite so daunting. There are also a few cases where it's difficult to decide because the choice is very arguable. And in other cases, having a clear set of rules of thumb can guide you to an appropriate decision.

Basic approach to choosing a collection
The overall approach I'd suggest for choosing is as follows:
1.choose the general type of organisation that your data needs to have (e.g. map or list); without too much thought, this is usually fairly clear;
2.then, choose the implementation of that type that has the minimum functionality that you actually require (e.g. don't choose a sorted structure if you don't actually need the data to be sorted).

People who read this post also read :



1 comments:

Hi There,
Thank you for sharing the knowledgeable blog with us I hope that you will post many more blog with us:-
Buy/order nembutal capsules powder injections from a reputable online pharmacy without prescription and guaranteed overnight delivery. At Flexi Pharmacy, we offer the best brands/generic prescription medications at cheap rate.
EmailId : info@flexipharmacy.com
Click here for more information:- more info

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More