Suggestion for 7. Iterating over an Arraylist Update: ignore this lol


#1

Coming from Python, I became heavily dependent on the
"for x in y" format for lists, so instead of having this format for iterating

for (int i = 0; i < quizGrades.size(); i++) {

    System.out.println( quizGrades.get(i) );

}

I would simply do this:

for int in quizGrades:
  print int

So I found out that in java, there is something similar that could be used to solve the problem in the excercise!
Personally, I think that

for (int temps : weeklyTemperatures ){
      System.out.println(temps);}

looks much better than

for (int i = 0; i < weeklyTemperatures.size(); i++) {

    System.out.println( weeklyTemperatures.get(i) );
}

But of course the code checking system does not accept the code that I came up with, because it checks if you used the .get() method and int j, which is why I'm suggesting that maybe it should accept both answers.


#2

Update: I just realized the format I tried is exactly what the next section talks about LOL
I guess I got a little ahead of myself XD

also why in the next exercise does it consider my code incorrect if I use int instead of Integer for specifying the type of variable?


#3

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