Files
java-interview-lab/stack-queue/output/10-stack-vs-arraydeque.txt
T

20 lines
777 B
Plaintext

java.util.Stack versus ArrayDeque used as a stack
=================================================
ArrayDeque as a stack: push(1), push(2), push(3), then pop until empty -> [3, 2, 1]
ArrayDeque as a queue: offer(1), offer(2), offer(3), then poll until empty -> [1, 2, 3]
push(1), push(2), push(3), then iterate:
java.util.Stack -> [1, 2, 3] (bottom to top)
ArrayDeque -> [3, 2, 1] (top to bottom)
Stack.class.getSuperclass() = java.util.Vector
Stack.pop() is synchronized = true
ArrayDeque.pop() is synchronized = false
push(null) on Stack = accepted
push(null) on ArrayDeque = java.lang.NullPointerException
ArrayDeque: push(1), push(2), peek() = 2 (push is addFirst)
ArrayDeque: offer(1), offer(2), peek() = 1 (offer is addLast)