How to iterate a List of objects in Java?

To iterate a List of objects in Java, use the for-each loop like so: for (var item : list).

Here's how you do it:

java.util.List<Integer> list = java.util.List.of(1, 2, 3);

// 1
// 2
// 3
for (var item : list) {
  System.out.println(item);
}