13/13 Did it, but didn't quite understand

In this exercise, we were asked to make an ArrayList named “sports”. However, we are then asked to print the elements inside the “sport” ArrayList (no “s”). I thought the console will show an error, but turns out it understood that I wanted the elements inside the “sportS” ArrayList.

Can anyone please explain?



public class GeneralizationsD {
	public static void main(String[] args) {

		ArrayList<String> sports = new ArrayList<String>();

    sports.add("Football");
    sports.add("Boxing");

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


pay attention to your for loop you create a variable sport that then refers to sports and to print out the array sports you would call it by the variable that you assigned in your for loop. :grin:

Wow, i feel stupid right now :joy:. Anyway, thanks a lot!

1 Like

You’re super welcome :grin: Feel free to click the solution button below my reply if that was the answer you were looking for. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.