Help, i don't understand


#1

Ok so when i say

for(String sport : sports) {
System.out.println(sport);
}

how is it picking up that when i am saying sport to list the sports because the array list is called sports not sport


#2

In the advanced for loop, you are creating a temporary variable which stores the current iterated element from your list/array.

Your code basically translates to: "For each element in the list 'sports', create a temporary variable called 'sport' and do something with it."

This would work just as well:

for (String myTemporaryVariable : sports) {
    System.out.println(myTemporaryVariable);
}

When naming lists and using for loops, people often use the singular version of a word (sports --> sport; bananas --> banana; items --> item; etc) because it makes it easier to understand what's happening in the code.