Main Page

Previous Next

Understanding the Collection Classes

The collection classes in java.util support various ways for you to store and manage objects of any kind in memory. They include a professional implementation of a linked list that we took so much trouble to develop for ourselves back in Chapter 6. If you want an array that automatically expands to accommodate however many objects you throw into it, or you need to be able to store and retrieve an object based on what it is, rather than using an index or a sequence number, then look no further. You get all this and more in the collection classes.

We'll be exploring the following capabilities provided by the package:

Class/Interface

Description

The Iterator interface

Declares methods for iterating through elements of a set, one at a time.

The Vector class

Supports an array-like structure for storing any type of object. The number of objects that you can store in a Vector object increases automatically as necessary.

The Stack class

Supports the storage of any type of object in a push down stack.

The LinkedList class

Supports the storage of any type of object in a doubly-linked list.

The HashMap class

Supports the storage of any type of object in a hash table, sometimes called a map.

We'll start by looking in general terms at various possible types of collections for objects.

Previous Next
JavaScript Editor Java Tutorials Free JavaScript Editor