Stack

The concept of the stack was introduced earlier, with the LinkedList.Whats rather odd about the Java 1.0/1.1 Stack is that instead of using a Vector as a building block, Stack is inherited from Vector. So it has all of the characteristics and behaviors of a Vector plus some extra Stack behaviors. Its difficult to know whether the designers consciously thought that this was an especially useful way of doing things, or whether it was just a naïve design; in any event it was clearly not reviewed before it was rushed into distribution, so this bad design is still hanging around (but you should never use it).

Heres a simple demonstration of Stack that pushes each line from a String array:

Each line in the months array is inserted into the Stack with push( ), and later fetched from the top of the stack with a pop( ). To make a point, Vector operations are also performed on the Stack object. This is possible because, by virtue of inheritance, a Stackis a Vector. Thus, all operations that can be performed on a Vector can also be performed on a Stack, such as elementAt( ).

As mentioned earlier, you should use a LinkedList when you want stack behavior.