public void insert(E element) {
        if (size == array.length) {
            Object[] doubledArray = new Object[size * 2];
            for (int i = 0; i < array.length; i++) {
                doubledArray[i] = array[i];
            }
            this.array = doubledArray;
        }
        array[size] = element;
        size++;
    }