首页  

Stack ArrayDeque LinkedList     所属分类 java 浏览量 142
Stack 继承 Vector 
LIFO last-in-first-out  
public Vector() {
        this(10);
}
Stack   初始容量 10 
 
ArrayDeque LinkedList 实现 Deque 接口
deque   double ended queue

ArrayDeque LinkedList 可以用来实现 Stack
push pop peek 


push addFirst
pop  removeFirst


public ArrayDeque() {
        elements = new Object[16];
}

ArrayDeque 初始容量 16


Stack	  ArrayDeque	                LinkedList
push(e)	  addFirst(e)  /offerFirst(e)	addFirst(e)/offerFirst(e)
pop()	  removeFirst()/pollFirst()	    removeFirst()/pollFirst()
peek()	  getFirst()   /peekFirst()	    getFirst()/peekFirst()

一般不推荐使用Vector以及其子类Stack


Stack<String> stack = new Stack<>(); ArrayDeque<String> arrayDeque = new ArrayDeque<>(1); LinkedList<String> linkedList = new LinkedList<>(); stack.push("a"); stack.push("b"); stack.push("c"); while(!stack.isEmpty()) { System.out.print(stack.pop()+" "); } System.out.println(); // addFirst arrayDeque.push("a"); arrayDeque.push("b"); arrayDeque.push("c"); while(!arrayDeque.isEmpty()) { // pop removeFirst System.out.print(arrayDeque.pop()+" "); } System.out.println(); linkedList.addFirst("a"); linkedList.addFirst("b"); linkedList.addFirst("c"); while(!linkedList.isEmpty()) { System.out.print(linkedList.pop()+" "); } System.out.println();

上一篇     下一篇
kafka Coordinator 简介

云原生时代的Java

进程io监控命令iopp

java线程状态及转换

LockSupport简介

ReentrantLock原理