If you want a dynamically sized collection I would recommend using a List (like ArrayList).
This is a simple example of how it works:
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
System.out.println("My List:" + list);
Output:
My List:[1, 2, 3]
You have to import java.util.ArrayList and java.util.List to be able to use them.
You can also iterate over the List like this:
for(int val : list) {
System.out.println("value: " +val);
}
Output:
value: 1
value: 2
value: 3
or iterate with an index:
for(int i=0; i<list.size(); i++){
System.out.println("value " + i + ": " + list.get(i));
}
Output:
value 0: 1
value 1: 2
value 2: 3
(Note that the indexes are 0-based; i.e. they start at 0, not 1)
For further information, please read the two Javadocs linked above for List and ArrayList