Selecting the Best Java Collection Class for Your Application
Java provides classes that implement the Collection interface to contain a collection of objects. There are over 20 of these collection classes, each having different performance and organizing properties.
This article explains how to choose the most appropriate of these classes for a particular use.
Table 1 shows a list of the concrete classes that Java 1.6 provides.
The classes in the java.util and java.util.concurrent packages are general purpose and have a wide range of uses. In contrast, the classes in the other packages are very specialized and used only for specific purposes with other classes in their individual packages.
- The classes in the java.beans.beancontext package support bean contexts for JavaBeans development.
- The classes in the javax.management and javax.management.relation packages are management beans that support remote administrative interfaces for programs.
- The class in the javax.print.attribute.standard package is used by that package to help describe the current state of a print job.
That leaves 20 general-purpose classes to sort through. The most useful way to classify these is into two categories: how they organize objects, and how long they take to perform various operations. For most uses, how a Collection class organizes objects is more important than how quickly it can add, find, or remove them. Knowing that, let's focus on how these classes organize objects.
Page 1 of 4