The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.

The List Abstract Class

The java.util package defines an abstract class called List that specifies the set of operations a class has to implement in order to be considered (very abstractly) a list. This does not mean, of course, that every class that implements List has to be a linked list.

Not surprisingly, the built-in LinkedList class is a member of the List abstract class. Surprisingly, so is Vector.

The methods in the List definition include add, get and iterator. In fact, all the methods from the Vector class that we used to implement Table are defined in the List abstract class.

That means that instead of a Vector, we could have used any List class. In we can replace Vector with LinkedList, and the program still works!

This kind of type generality can be useful for tuning the performance of a program. You can write the program in terms of an abstract class like List and then test the program with several different implementations to see which yields the best performance.

Last Update: 2011-01-24