You would definitely need to reassign the original array, as arrays do have a fixed size. This tiny example does illustrate how it could be done.
public class A {
private int i;
public A(int i) {
this.i = i;
}
public static void main(String[] args) {
// Original array with the size 1;
A[] arr = new A[1];
// One default item
arr[0] = new A(0);
// Reassign array here, use a method returning a new instance of A[]
arr = add(arr, new A(1));
// just for printing.
for(A a : arr) {
System.out.println(a.i);
}
}
public static A[] add(A[] inputArr, A newItem) {
// The array will have another item, so original size + 1
A[] buffer = new A[inputArr.length+1];
// Copy the original array into the new array.
System.arraycopy(inputArr, 0, buffer, 0, inputArr.length);
// Add the new item at the end
buffer[buffer.length-1] = newItem;
// Return the "increased" array
return buffer;
}
}
The output now shows you have two items in the array.
O/P:
0
1
All in all it would be better to use a List
here, but as you don´t want it i hope that this example can guide you to a way of doing it with arrays.