Difference between declaring variables before or in loop?

Ads

 
 

Share on Google+Share on Google+

Java Coder
Difference between declaring variables before or in loop?
1 Answer(s)      3 years and 10 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.


Ads









Related Tutorials/Questions & Answers:
Advertisements

Ads

 
Advertisement null

Ads