Stack
1. Implement stack function by inheriting vector class
2. Increase the synchronization method, thread safety, low efficiency
PackageJava.util;public class Stack<e> extends Vector<e> { /** * Create stack * /Public Stack () {}/** * into the stack * @return the <code>item</code> argument. * @see java.util.vector#addelement * *Public e push (e Item) {addelement (item);returnItem }/** * * @return The object at the top of this stack (the last item * of the &L T;tt>vector</tt> object). * @throws emptystackexception If this stack is empty. */Public synchronized e pop () {e obj; int len = size (); obj = Peek (); Removeelementat (Len-1);returnObj }/** * Stack top element * * @return The object at the top of this stack (the last item * of the <tt>Vector</tt> object). * @throws emptystackexception If this stack is empty. */Public synchronized E Peek () {int len = size ();if(len = =0)Throw NewEmptystackexception ();returnElementAt (Len-1); }/** * is empty * * @return <code>true</code> if and only if the this stack contains * No items; <code>false</code> otherwise. */public Boolean empty () {returnSize () = =0; }/** * Find the ID of element o * * @param o the desired object. * @return The 1-based position from the top of the stack where * the object is located; The return value <code>-1</code> * Indicates, the object is not on the stack. */public synchronized int search (Object o) {int i = lastIndexOf (o);if(I >=0) {returnSize ()-I; }return-1; }/** use Serialversionuid from JDK 1.0.2 for interoperability * / PrivateStaticFinalLong Serialversionuid =1224463164541339165L;}
Stack class source code parsing