public interface Deque<E> extends Queue<E> {
}
import java.util.Deque;
import java.util.LinkedList;
public class ArrayListDemo04 {
public static void main(String[] args) {
//栈
Deque<String> deque = new LinkedList();
deque.push("A1");//入栈
deque.push("A2");
deque.push("A3");
System.out.println(deque);//[A3, A2, A1]
System.out.println(deque.size());//3
System.out.println(deque.peek());//获取栈顶元素 A3
while(!deque.isEmpty()){
String pop = deque.pop();//出栈
System.out.println("出栈:"+pop);
}
}
}
执行结果:
[A3, A2, A1]
3
A3
出栈:A3
出栈:A2
出栈:A1
Process finished with exit code 0
原文:https://www.cnblogs.com/zhangyaru/p/15051059.html