After learning the vector, we then began to learn stack. Stack is simple, it inherits from Vector. Learn the same way as before, first stack has a general understanding, and then learn its source, and finally through the example to learn to use it.
1th Part Stack Introduction
Stack Introduction
Stack is a stack. Its characteristics are: Advanced and Out (FILO).
The stack in the Java Toolkit is inherited from vectors (vector queues), because vectors are implemented through arrays, which means that stack is also implemented through arrays, not linked lists. Of course, we can also use LinkedList as a stack!
Inheritance relationships for stack
Java.lang.Object
java.util.abstractcollection<e>
java.util.abstractlist<e>
java.util.vector<e>
java.util.stack<e> Public
class Stack<e> extends Vector<e> {}
The relationship between stack and collection is shown in the following diagram:
The constructor for the stack
Stack has only one default constructor, as follows:
Stack ()
Stack's API
Stack is a stack, and its common APIs are as follows:
Boolean empty ()
Synchronized E Peek ()
Synchronized E pop ()
E push (E object)
synchronized int search (Object o)
Because it is stack and inherits from Vector, it also contains all the APIs in the vector.