栈Stack
栈的特点:后进后先
* 初始化Stack
stack=new Stack<>(); * 栈的特点:先进后出 * Object push(Object
obj)压栈:压入栈顶/或add效果相同 * Object pop()弹栈:移除栈顶 * Object
peek()查看栈顶,但不弹栈 * boolean
isEmpty()返回:栈是否为空,用法如 1 2 3
| while(!stack.isEmpty){ do some thing }
|
1 2 3 4 5 6 7 8
| public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Stack<Integer> stack=new Stack<>(); scan.close(); } }
|