I want to ask which piece of code is more efficient in Java? Code 1:
void f() { for(int i = 0 ; i < 99999;i++) { for(int j = 0 ; j < 99999;j++) {
The second is worse.
Why? Because the loop variable is scoped outside the loop. i and j will have a value after the loop is done. Generally that isn't what you want. The first scopes the loop variables so it's only visible within the loop.
i
j