for(String s : stringArray) {
doSomethingWith(s);
}
How do I know how many times I repeat this if I have this for-each syntax? for(inti=0;i<boundary;i++) The value of i is the number of iterations In a for-each statement
int i = 0;
for(String s : stringArray) {
doSomethingWith(s);
i++;
}
Is this the only way you can do it?
for-loop loops java foreach
Yeah, that's the simplest way. The for-each statement does not have an internal counter.
Use stringArray.length to see the actual number of for statements.
© 2024 OneMinuteCode. All rights reserved.