Your method won't work because clone()
will just reassign the array to the original size. I would recommend using
System.arraycopy(OrigArray, 0, tempArray, 0, OrigArray.length);
instead.
Also, the most efficient way of doing this would be to use an ArrayList
, since they implement practically the same thing, but clean up your code a lot.
The only problem is when you need to get a regular array of the value's type, then you would have to do this:
String[] asArr = new String[OrigArray.length];
for(int i = 0; i < OrigArray.length; i++)
asArr[i] = OrigArray.get(i);
Here is the Javadoc for ArrayList
:
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html