protected void extendArray ( int k ) { // size + 1 could overflow if ( this . size + k > this . keys . length ) { int newCapacity ; if ( this . keys . length < 1024 ) { newCapacity = 2 * ( this . size + k ) ; } else { newCapacity = 5 * ( this . size + k ) / 4 ; } this . keys = Arrays . copyOf ( this . keys , newCapacity ) ; this . values = Arrays . copyOf ( this . values , newCapacity ) ; } }
make sure there is capacity for at least k more elements