0

For each know last iteration

In Java for each how i know the last iteration without adding a new variables? For (int n : numbers){ // How i know the last iteration? }

15th Jan 2022, 1:07 PM
Marco Ginato
Marco Ginato - avatar
2 Réponses
+ 2
int len = numbers.length - 1; for(int n : numbers){ if(n == numbers[len]){ // do something } }
15th Jan 2022, 2:51 PM
Avinesh
Avinesh - avatar
0
yes is correct, but my question was without adding new variable. It's seems there is nothing method. I have midified original question thanks ;)
15th Jan 2022, 8:07 PM
Marco Ginato
Marco Ginato - avatar