Java Programming/Collections

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search
Navigate Collection topic: ( v d e )
Development stage: 75% (as of Jul 01, 2006) Collection or Map
Development stage: 75% (as of Jul 01, 2006) Collection
Development stage: 75% (as of Jul 01, 2006) Map
Development stage: 75% (as of Jul 01, 2006) Set or List or Queue
Development stage: 75% (as of Jul 01, 2006) Set
Development stage: 75% (as of Jul 01, 2006) List
Development stage: 75% (as of Jul 01, 2006) Queue
Development stage: 75% (as of Jul 23, 2006) Map Classes
Development stage: 75% (as of Jul 23, 2006) Thread Safe Collections
Development stage: 75% (as of Jul 23, 2006) Classes Diagram (UML)
Beginners Topics:

Whenever we need to group objects, or we need to reference a group of objects, instead of one object, we can use Java Aggregate(Collection) classes. There are two main interfaces, those are java.util.Collection and java.util.Map . Implementations for those interfaces are not interchangeable.

The implementations of java.util.Collection interface are used for grouping simple java objects.

The implementations of java.util.Map interface are used to represent mapping between "key" and "value" objects. A Map represents a group of "key" objects, where each "key" object is mapped to a "value" object.

Example of using Collection 
We can group together all patients in a Hospital to a "patient" collection.
Example of using Map 
For each patient, there is one and only one main nurse assigned to. That association can be represented by a "patient-nurse" Map.

Note that the above associations are explicit, the objects themself do not have any knowledge/information about that their are part in an association. But that is the main idea about using the aggregate/collection classes; that is to create explicit associations between simple java objects.

In other languages