Enhanced For loop vs ForEach Loop

Hi,

what are differences. practical uses of Enhanced For loop vs ForEach Loop. When to use which one. Why one is called external iterator and other as internal iterator, please advise
LVL 7
gudii9Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CPColinConnect With a Mentor Senior Java ArchitectCommented:
There are barely any differences between the two strategies, so use whichever one produces code that is easier for you to understand.
0
 
CPColinSenior Java ArchitectCommented:
In Java, the terms "enhanced for loop" and "foreach loop" refer to the same thing. Can you post a link to where you read that they were different?
0
 
krakatoaConnect With a Mentor Commented:
for(int i=0;i<100;i++){
System.out.println(i);
}

Open in new window


... you are responsible for the halt condition.
int[] integers ={1,2,3};
for(int i: integers){System.out.println(i);
}

Open in new window

... Java handles the stop condition.
0
 
gudii9Author Commented:
i mean java 8 for each with lamda

https://www.mkyong.com/java8/java-8-foreach-examples/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.