码迷,mamicode.com
首页 > 其他好文 > 详细

Stack

时间:2015-05-27 20:57:03      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

import java.util.Stack;

public class StackTest {
	public static void main(String[] args) {
		Stack<String> stack = new Stack<String>();
		System.out.println("now the stack is " + isEmpty(stack));
		stack.push("1");
		stack.push("2");
		stack.push("3");
		stack.push("4");
		stack.push("5");
		System.out.println("now the stack is " + isEmpty(stack));
		System.out.println(stack.peek());
		System.out.println(stack.pop());
		System.out.println(stack.pop());
		System.out.println(stack.search("2"));
	}
	
	public static String isEmpty(Stack<String> stack) {
		return stack.empty() ? "empty" : "not empty";
	}
}

  

now the stack is empty
now the stack is not empty
5
5
4
2

 

search(Object o)

Returns the 1-based position where an object is on this stack.

 

Stack

标签:

原文地址:http://www.cnblogs.com/lnas01/p/4534346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!