Stack class source code parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.