miercuri, 29 iunie 2011

The Java Collections Framework - a summary

Seems like when talking Java, there's a cooler approach to solving problems related to lots of similar data objects, other than the good old arrays.

Java 2 introduces the Collections Framework.

My experience with learning it (not mastering it though) is summed up like this: It sounds far more scary than it is. It is based on 3 concepts that anyone will get, as soon as they're presented. Quite important concepts though, they are: interfaces, implementations and algorithms.

I sure as hell didn't need anyone presenting me anything more than this, but it seems everyone's so zealous, you just can't get that good piece of info that you actually need.

Anyway, the interfaces are:
Collection - the generic interface - check it in the javadoc.
Set - it's a collection that doesn't support duplicates.
List - does allow duplicates.
Map - a collection of type (key : value)

The implementations for them are many, and i won't go into details about them, because they have confused me, and all the decisions i ever needed to make about them were easy once i knew what's up with the 4 interfaces.
Some things you need to know, specified by the creators of the Java collections framework is this: mutability is better used only if extremely necessary. if you just want to read stuff from your collections, make them immutable with the methods provided with the methods provided by the algorithms.

And finally, the algorithms for the collections (the sorting, the ordering, creating sub-sets, generating special collections) you will find in the classes
Collections
Arrays

Have fun with the collections!

Here's an excellent far more in-depth 44 page article describing the JCF
Here's the uml for the whole thing

Niciun comentariu:

Trimiteți un comentariu