先进后出

接口设计:

◼ int size(); // 元素的数量
◼ boolean isEmpty(); // 是否为空
◼ void push(E element); // 入栈
◼ E pop(); // 出栈
◼ E top(); // 获取栈顶元素
◼ void clear(); // 清空

public class Stack<E> {
	private List<E> list = new ArrayList<>();
	
	public void clear() {
		list.clear();
	}
	
	public int size() {
		return list.size();
	}

	public boolean isEmpty() {
		return list.isEmpty();
	}

	public void push(E element) {
		list.add(element);
	}


	public E pop() {
		return list.remove(list.size() - 1);
	}


	public E top() {
		return list.get(list.size() - 1);
	}
}
原文地址:https://www.cnblogs.com/xiuzhublog/p/12608556.html