Program 21.1: A String stack

Stacks in Java are a subclass of java.util.Vector, and they share with Vector the weakness of requiring the objects stored in the stack to be objects. For example program 21.1 is a subclass of Stack that holds only Strings.

public class StringStack extends java.util.Stack {

  public Object push(Object item)
    super.push((String) item);


Copyright 1996, 2003 Elliotte Rusty Harold
This Chapter