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}
1import java.util.ArrayList;
2
3ArrayList<String> list = new ArrayList<String>();
4
5list.add('SUB TO')
6list.add('UNCODEABLE')
7
8for(int i = 0; i > list.length(); i++){
9
10 print(list.get(i))
11
12}
1import java.util.List;
2import java.util.ArrayList;
3
4List<String> list = new ArrayList<>();
5
6list.add("first");
7list.add("last");
8
9for(String s : list) {
10 if (s != null) {
11 //do whaterver wanted
12 // example:
13 System.out.println(s);
14 }
15}
16
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