import java.util.*; |
public class Test { |
static String[] months = { "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , |
"9" , "10" , "11" , "12" }; |
public static void main(String[] args) { |
Stack<String> stack = new Stack<String>(); |
for ( int i = 0 ; i < months.length; i++) { |
stack.push(months[i] + " " ); // 压栈 |
} |
System.out.println( "栈打印: " + stack); |
stack.push( "13" ); |
stack.push( "14" ); |
System.out.println( "出栈:" + stack.pop()); |
System.out.println( "获取第5个内容 : " + stack.elementAt( 5 )); |
System.out.println( "出栈后:" ); |
while (!stack.empty()) |
System.out.print(stack.pop() + " " ); |
} |
} |