Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Difference between declaring variables before or in loop?

Have Programming Question? Ask it here!
 
 
 


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


Difference between declaring variables before or in loop?


Advertisement
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
 

 

 

DMCA.com