import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class MainClass {
public static void main(String[] args) {
List list = Arrays.asList("A", "B", "C", "D");
Iterator iterator = list.iterator();
while (iterator.hasNext () ) {
String element = (String) iterator.next ();
System.out.println(element);
}
}
}
A
B
C
D
This is identical to:
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class MainClass {
public static void main(String[] args) {
List list = Arrays.asList("A", "B", "C", "D");
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
String element = (String) iterator.next();
System.out.println(element);
}
}
}
A
B
C
D