Today's day code, encountered stack stack class, special view Java API documentation, summarized as follows:
Stack inherits the Vector class.
The stack is characterized by LIFO.
The method of stack itself is not many in the API, it is related to the characteristic of stack basically.
Examples are attached, follow-up continues to summarize
/** * @ Author WHS * @ Creation Date February 4, 2015 * @ Version V 1.0 */package Thread.pool;import Java.util.stack;public class Stackexam {public St atic void Main (string[] args) {stack<string> Stack = new stack<string> (); System.out.println ("Now the Satck is" +isempty (stack)), Stack.push ("1"), Stack.push ("2"), Stack.push ("3"); Stack.push ( "4"); Stack.push ("5"); Stack.push ("6"); System.out.println ("Now the Stack is" +isempty (stack)); System.out.println (Stack.peek ());//View the object at the top of the stack and return the object, but do not remove it from the stack. System.out.println (Stack.pop ()); System.out.println (Stack.pop ()); System.out.println (Stack.search ("3"));//, this method returns the distance from the top of the stack where the nearest target object appears to the top of the stack;}public static String IsEmpty (stack< String> stack) {return stack.empty ()? "Empty": "Not Empty";}}
The output is:
Now the SATCK are emptynow the stack is not empty6652
Java Collection Class--stack stack class