A possible solution to create dynamic arrays in Java (homework for university lecture - introduction to data structures and algorithms)