Collections

From Wikibooks, open books for an open world
Jump to: navigation, search

Class Loading Java Programming
Collections
Collection Classes
Navigate Collection topic: v  d  e )
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 them-self 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.


Class Loading Java Programming
Collections
Collection Classes