This period of time to look at crazy JAVA again, found that Stack, ArrayDeque, LinkedList can be used as a Stack, so slightly from the performance and implementation details of the comparison of these three differences.

Class inheritance tree


The difference between

Underlying data storage mode

  storage
Stack An array of length 10
ArrayDeque Array of length 16
LinkedList The list

Method reference table

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

Thread safety

  Thread safety
Stack Thread synchronization
ArrayDeque Thread out of sync
LinkedList Thread out of sync

Performance options

In general, Vector and its subclasses Stack are not recommended

1. Thread synchronization is required

Convert out-of-sync ArrayDeques and LinkedLists into thread synchronization using synchronizedXxx() in the Collections utility class.

2. Frequent insert and delete operations: LinkedList

3. Frequent random access operations: ArrayDeque

4. Unknown initial data volume: LinkedList