java List.forEach code example
Example 1: java foreach list
list.forEach((MyType myObject) -> {});
Example 2: java foreach
List<String> someList = new ArrayList<String>();
for (String item : someList) {
System.out.println(item);
}
Example 3: java loop through list
for (E element : list) {
. . .
}
Example 4: java go troght loop object
import java.util.List;
import java.util.ArrayList;
List<String> list = new ArrayList<>();
list.add("first");
list.add("last");
for(String s : list) {
if (s != null) {
System.out.println(s);
}
}
Example 5: iterate a list using iterator
Iterator<String> crunchifyIterator = crunchifyList.iterator();
while (crunchifyIterator.hasNext()) {
System.out.println(crunchifyIterator.next());
}