Java for Loop

Java Conventions - Stepping Through a List

There are many ways in Java to loop through a list.

Our Tips:

  • We prefer not to use while statements.
  • We prefer not to use iterators.
  • We prefer to use for statements.

For statements know how many items are in a list and so they require less code.


List<Integer> a = new ArrayList<Integer>();

for (Integer integer : a)