Help the world stop coronavirus! Stay home!

Prev Next

Java / Control Statements

Advantages of declaring loop variable as final in enhanced for-loop.

  • Enables using the loop variable in an anonymous inner class within the loop body.
for (final int i : intList) {
	Runnable run = new Runnable() {
		public void run() {
			process(i);
		}
	};
	new Thread(run).start();
}
  • It prevents the loop variable to be accidently changed inside the loop while iterating.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Access Modifiers

Comments & Discussions