1int[] nums = new int[5];
2for(int i = 0; i < nums.length; i++){
3 nums[i] = i + 2;
4 System.out.println(nums[i]);
5}
6/*
7 OUTPUT:
8 2 3 4 5 6
9 each time i is increased by 2
10*/
1// A better solution would be to use an ArrayList which can grow as you need it.
2// The method ArrayList.toArray( T[] a )
3// gives you back your array if you need it in this form.
4
5List<String> where = new ArrayList<String>();
6where.add(element);
7where.add(element);
8
9// If you need to convert it to a simple array...
10
11String[] simpleArray = new String[ where.size() ];
12where.toArray( simpleArray );