Jump to content

Java Collections API

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ed Poor (talk | contribs) at 07:48, 21 March 2002 (just a little summary, off the top of my head). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

The Java Collections API contains classes and methods that facilitate the grouping and organization of objects.

The List interface enables the programmer to aggregate objects and then traverse the list, as when performing some operation on each of the list's members.

The Set interface enforces the rule that no two objects it contains are equal to each other. An OrderedSet (backed by a TreeSet) keeps the objects in order.

A Map maintains a one-to-one mapping of key to object -- handy for doing look-ups. For example, if you know a City, you can use a Map to find look up the corresponding Country.

Objects are kept in order by using a Comparator whose compareTo method defines a natural ordering of objects. Often the compareTo method is defined in the class definition of the objects themselves, rather than being in a separate Comparator object.