You can’t resize an array in Java. You’d need to either:
-
Create a new array of the desired size, and copy the contents from the original array to the new array, using
java.lang.System.arraycopy(...);
-
Use the
java.util.ArrayList<T>
class, which does this for you when you need to make the array bigger. It nicely encapsulates what you describe in your question. -
Use
java.util.Arrays.copyOf(...)
methods which returns a bigger array, with the contents of the original array.