1MyObject objects[] = new MyObject[6];
2for (MyObject o: objects) {
3
4 o = new MyObject();
5}
6
7MyObject objects[] = new MyObject[6];
8for(int i = 0; i < objects.length; i++) {
9
10 objects[i] = new MyObject();
11}
1ArrayList<String> namesList = new ArrayList<String>(Arrays.asList( "alex", "brian", "charles") );
2
3for(int i = 0; i < namesList.size(); i++)
4{
5 System.out.println(namesList.get(i));
6}
7
1// Using the range of int i we assign new objects to the List using i as the index
2List<Objects> objects = new ArrayList<>();
3
4for (int i = 0; i < 10; i++)
5{
6 // Generate or get variables
7 objects.add(i, new Object(variable, variable1));
8}
9