Cannot we use a Java for-each loop for this?