Java, like many general-purpose languages, provides several tools for creating generic classes. Different requirements will necessitate using different tools. In this column I will use the development of a container class as an example since it can accommodate nearly all of the tools a user might wish to use. A definition For those of you who are not yet familiar with things object-oriented, a container is a class that organizes other objects. Common containers are binary trees, queues, lists, and stacks.
Containers have both an organizing principle and an interface.
Simple containers can be thought of as having the standard methods add and remove . Further, they will have a means to enumerate the entire container, to check to see if a candidate object is already in the container and to test the number of elements being held by the container. The non-keyed containers like Stack and Vector simply stuff objects in and pull objects out. The keyed container Hashtable uses a key object to locate a data object. HashCode that returns a unique hash code for every object.