The for-each loop in Java uses the underlying iterator mechanism. So it's identical to the following:
Iterator<String> iterator = someList.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
System.out.println(item);
}
The for-each loop in Java uses the underlying iterator mechanism. So it's identical to the following:
Iterator<String> iterator = someList.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
System.out.println(item);
}