Java Stack类 使用
http://blog.csdn.net/wodwl/article/details/4368759
java.util.*;
例:
Stack<Integer> stack = new Stack<Integer>();
stack.push(3);
stack.push(4);
System.out.println(stack);
int a = stack.pop();
System.out.println(a);
System.out.println(stack);
System.out.println(stack.peek()); // 查看栈顶元素而不移除它
System.out.println(stack);
Stack stack2 = new Stack();
stack2.push("a");
stack2.push("b");
stack2.push(1);
stack2.push(1.2);
System.out.println(stack2);
double b = (double)stack2.pop(); // 必须有强制类型转换成与栈中相符的类型
System.out.println(b);
结果:
[3, 4]
4
[3]
3
[3]
[a, b, 1, 1.2]
1.2