1List<String> someList = new ArrayList<String>();
2// add "monkey", "donkey", "skeleton key" to someList
3for (String item : someList) {
4 System.out.println(item);
5}
1List<Integer> data = new ArrayList<>();
2
3//Indexed Loop
4for(int i = 0,size=data.size();i<size;i++){
5 System.out.println(data.get(i));
6}
7
8//For each loop
9for(Integer element : data){
10 System.out.println(element);
11}
12
13//Using forEach
14data.forEach(System.out::println);
15
16//Using Stream
17data.stream().forEach(System.out::println)
18
19//While loop
20int i = 0;
21while(i<data.size()){
22 System.out.println(data.get(i++));
23}
24
25