1Iterator itr=list.iterator();
2while(itr.hasNext()){
3 system.out.println(itr.next);
4}
1for (int i = 0; i < crunchifyList.size(); i++) {
2 System.out.println(crunchifyList.get(i));
3 }
1// will iterate through each index of the array list
2// using the size of the array list as the max.
3// (the last index is the size of the array list - 1)
4
5for (int i = 0; i < myArrayList.size(); i++) {
6
7 System.out.println(myArrayList.get(i));
8 // will print each index as it loops
9}
1Iterator<String> crunchifyIterator = crunchifyList.iterator();
2 while (crunchifyIterator.hasNext()) {
3 System.out.println(crunchifyIterator.next());
4 }
1import java.util.ArrayList;
2import java.util.Iterator;
3
4public class IteratorSample {
5 public static void main(String[] args) {
6 ArrayList<String> list = new ArrayList<String>();
7 list.add("JavaFx");
8 list.add("Java");
9 list.add("WebGL");
10 list.add("OpenCV");
11 Iterator iterator = list.iterator();
12 while(iterator.hasNext()) {
13 System.out.println(iterator.next());
14 }
15 }
16}