Java-Stack source code analysis and examples, java-stack source code examples
Come to the end of the paper, and never know how to do this-Lu YouWenqu that clear such, for the source of live water to Zhu Xi
Stack is a Stack with the feature of First In Last Out (FILO, First In Last Out ). Stack inherits from Vector (Vector Queue). Because Vector is implemented in the same array, Stack also uses arrays instead of linked lists. The Relationship Between Stack and Collection is as follows:
Java 8-based source code:
Public class Stack <E> extends Vector <E> {public Stack () {// create an empty Stack} public E push (E item) {// inbound Stack addElement (item ); return item;} // public synchronized E pop () {E obj; int len = size (); obj = peek (); removeElementAt (len-1 ); return obj;} // return the top element of the stack, but the public synchronized E peek () {int len = size (); if (len = 0) throw new EmptyStackException (); return elementAt (len-1);} // judge whether the stack is empty public boolean empty () {return size () = 0 ;} // search for the element and return the stack depth public synchronized int search (Object o) {int I = lastIndexOf (o); if (I> = 0) {return size () -I;} return-1;} // sequence version number private static final longSerialVersionUID= 1224464254541339165l ;}
Copyright Disclaimer: knowledge is shared, and technology is for communication. Leave a blogger's link for reprinting.