You might want to take a look at Java Arrays API. It has a method copyOf
that allows you to create resized copies of arrays. The original array can’t be changed with it, though.
If you have to do this, however, I recommend you to listen to the advice in the comments and use a List
datastructure such as ArrayList
. It’s easier, less error-prone and likely even more efficient.