Object extendArray(Object array, int currentSize, int requiredSize)
    {
        if (requiredSize < currentSize) {
            return array;
        } else {
            Object newArray = null;
            int newSize = currentSize * 2;

            if (newSize <= requiredSize) {
                newSize = requiredSize + 1;
            }

            if (array instanceof char[]) {
                newArray = new char[currentSize * 2];
            } else if (array instanceof Object[]) {
                newArray = new Object[currentSize * 2];
            }

            System.arraycopy(array, 0, newArray, 0, currentSize);
            return newArray;
        }
    }