Java Coder
Difference between declaring variables before or in loop?
1 Answer(s)      2 years and 9 months ago
Posted in : Java Beginners

Difference between declaring variables before or in loop?

Ads

View Answers

December 23, 2013 at 6:07 PM


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.










Related Tutorials/Questions & Answers:
Advertisements

Ads

Advertisement