?
Solved

Enhanced For loop vs ForEach Loop

Posted on 2016-09-04
4
Medium Priority
?
255 Views
Last Modified: 2016-09-05
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
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41784241
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
 
LVL 16

Assisted Solution

by:krakatoa
krakatoa earned 1000 total points
ID: 41784386
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
 
LVL 7

Author Comment

by:gudii9
ID: 41785475
i mean java 8 for each with lamda

https://www.mkyong.com/java8/java-8-foreach-examples/
0
 
LVL 14

Accepted Solution

by:
CPColin earned 1000 total points
ID: 41785497
There are barely any differences between the two strategies, so use whichever one produces code that is easier for you to understand.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Six Sigma Control Plans
Starting up a Project
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question