Java Collection Class--stack stack class

Source: Internet
Author: User

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

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.