I am used to implement loops with generics like that:
for (final Dog lDog : lAllDog) {
...
}
Unfortunality for another business case I need the current count of the iteration. I know I can solve this by coding somthing like that:
for (int i = 0 ; i < lAllDog.length(); i++) {
System.out.println(i);
}
or
int i = 0;
for (final Dog lDog : lAllDog) {
...
i++;
}
but is there a way to get the current count of iteration with my first code example without declaring a new int
or change the whole loop header?
Thx a lot
Briefly, no. You have to use the indexing method to do that.
No, there is no other to get count of iteration other than you described in your question. You'll have to use old way to have counter defined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With