So I thought that it might be a good idea to try to make what is stated in the title. It has an initial size of 1x1 and can expand as much as you like. I figured it to be more convenient that having "String[][] matrix = new String[1][1];" and having to provide dimensions from the get go. Anyway, the code is obviously not perfect, feel free to use it and tell me if I've done anything wrong or hideously impractical.

or the method should be called isInValidPosition and the > should be >= then (like in put())

for optimization you could store in the outer loops a reference to

1

array[x]

and use this in the inner loops, but of course it depends on your matrix size and usage frequency if that makes sense and since you are using getters and setters in the loops i think it's not very time critical code

further, in the expand() method i would copy the area of Math.min(newWidth, getWidth()) and Math.min(newHeight, getHeight()) and remove the try catch. this way you can handle the case when newWidth > getWidth but newHeight < getHeight() for example.

in getSection() you could replace the inner loop with a System.arraycopy()

and so on

EDIT: damn how can i use the array index operator in normal text without getting this list thing?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org