栈是采用先进后出的数据存储方式,每一个栈都包含一个栈顶,每次出栈是将栈顶的数据取出。
Stack类
常用方法:
import java.util.Stack ; public class StackDemo{ public static void main(String args[]){ Stack<String> s = new Stack<String>() ; s.push("A") ; // 入栈 s.push("B") ; // 入栈 s.push("C") ; // 入栈 System.out.print(s.pop() + "、") ; System.out.print(s.pop() + "、") ; System.out.println(s.pop() + "、") ; System.out.println(s.pop()) ; } };如果栈中已经没有内容了,则无法继续出栈。