Difference between declaring variables before or in loop?
String str; for (int i = 0; i < 10; i++) { str = "my String"; }
Java - Declaring variable before loop is a good practice. like as given in the above code. We have declared the Variable string before the for loop.
It will help you in reducing the memory usage.
Ads