1: public void push(T newEntry)
2: {
3: checkInitialization();
4: ensureCapacity();
5: stack[topIndex + 1] = newEntry;
6: topIndex++;
7: } // end push
8:
9: private void ensureCapacity()
10: {
11: if (topIndex >= stack.length - 1) // If array is full, double its size
12: {
13: int newLength = 2 * stack.length;
14: checkCapacity(newLength);
15: stack = Arrays.copyOf(stack, newLength);
16: } // end if
17: } // end ensureCapacity
18: // Version 4.0