I hope you're not thinking that it's less efficient with the new style for loop because you're not re-using the variable. The Java compiler and the Java virtual machine are very smart with optimizations. Don't use the old-style loop only because you think that it's more efficient if you re-use the variable - that simply isn't true.
To me it was confusing how there is just one s, when I was thinking about it... And, when I was thinking about it, I would allways rather put String st, and not String on s... And there is no counter variable, which is for now something I would like to see still. So I got it like String "casts out" from the array, just that one s... at the time. Hm.. I just accepted it as it is, and never wondered about it, but now it it seems to me like an interesting question. Why it cant be reused? Can somebody easilly tell me how it is in other languages? Can that variable be reused in other languages? Hm?
Can somebody easilly tell me how it is in other languages? Can that variable be reused in other languages? Hm?
I doubt if such a comparison can be made. It would depend highly on how the compiler makes optimizations and even if the compiler were to allow you to reuse the variable it would be hard to say if that makes a difference to performance, especially in a language like java.
The bottom line is - you have to declare a variable. Leave the optimization worries to the compiler