Code example for EmptyStackException

0
		elements[size++] = e;
	} 
 
	public Object pop() {
		if (size == 0) {
			throw new EmptyStackException();
		} 
		Object result = elements[--size];
		elements[size] = null; // Eliminate obsolete reference
		return result;
	} 
 
	/* 
	 * Ensure space for at least one more element roughly doubling the capacity each time the array needs to grow 
	 */ 
	private void ensureCapacity() { 
		if (elements.length == size) {
			elements = Arrays.copyOf(elements, 2 * size + 1);
		} 
	} 
}