I know you can't dynamically expand a normal array but is this a valid way of doing it?
public int size = 0;
public String[] OrigArray = new String[size+1];
public void expand(){
String[] tempArray = new String[size+1];
tempArray = (String[])OrigArray.clone();
OrigArray = new String[size+1];
OrigArray = (String[])tempArray.clone();
size++;
}
I'm aware of much better methods than trying to use a normal array but I'd like to figure this for just using a normal array first.
My desire is that it starts off with OrigArray being 0+1 (so 1) and when expand() is called the new tempArray is made that is the same size as the OrigArray and this then holds OrigArray while OrigArray is declared again with size+1 then the tempArray is copied back to the newly sized OrigArray. This makes sense to me, but I keep getting out of bound exception?