java中Stack有什么用
Stack的用法
馬克-to-win:Stack稱為“后入先出”(LIFO)集合。
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
例:3.2.1
import java.util.*;
public class TestMark_to_win {
static String[] months = { "一", "二", "三" };
public static void main(String[] args) {
Stack stk = new Stack();
for (int i = 0; i < months.length; i++)
stk.push(months[i] );
System.out.println("stk = " + stk);
System.out.println("彈出 elements:");
while (!stk.empty())
System.out.println(stk.pop());
}
}
結(jié)果:
stk = [一, 二, 三]
彈出 elements:
三
二
一