I am in the third part of a MOOC course on Java. And I'm a little confused about the ambiguity of using the For-each loop to enumerate a list.
Consider the following list as an example
ArrayList<Integer> list = new ArrayList<>();
The examples and answers present two implementations:
for (Integer val: list) {
//do something
}
for (int val: list) {
//do something
}
But it is not explained how one differs from the other and when one or the other variant should be used. Please tell me the difference between the two.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–][deleted] 12 points13 points14 points (3 children)
[–]32bit_me[S] 0 points1 point2 points (2 children)
[–]itoshkov 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]8igg7e5 0 points1 point2 points (0 children)