There is no way to set the initial index of an array: it still has a 1st (index 0) element, it just happens to be null
in your case. You can always start iterating from whatever index you want, but you’ll be wasting space.
You could always make your own class…
class WeirdIndexArray<T> {
private final T[] internalArray;
public final int firstIndex;
public final int indexBound;
public WeirdIndexArray( int firstIndex, int size ){
internalArray = new T[size];
this.firstIndex = firstIndex;
indexBound = firstIndex+size;
}
public void set( int index, T item ){ internalArray[index-firstIndex] = item; }
public T get( int index ){ return internalArray[index-firstIndex]; }
}
And use it…
WeirdIndexArray<String> array = new WeirdIndexArray<>(1,3);
for( int i=1; i<array.indexBound; i++ )
array.set(i,"This is item "+i);
But why would you need that in the first place?
solved How do I start from a specified value in an array?