Solved

Enhanced For loop vs ForEach Loop

Posted on 2016-09-04
4
176 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 250 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 250 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

A short article about problems I had with the new location API and permissions in Marshmallow
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

724 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