Search code examples
javastackarraydeque

difference between the grow() methods in java.util.Stack and java.util.ArrayDeque


I came across the grow() method for when a stack is full, but when I saw there was a difference in the grow() function in the arraydeque, I wondered what the difference actually was.

Does anyone know the answer to this?

if (s == elementData.length){
    elementData = this.grow()
}

Solution

  • So eventually I found out that the differences are the following:

    Stack growable:

    1. Tight Strategy : Add a constant amount to the old stack (N+c)
    2. Growth Strategy : Double the size of old stack (2N)

    Arraydeque growable:

    'Array deques have no capacity restrictions and they grow as necessary to support usage.' arraydeque