File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What is the use of this New Enhanced for loop feature ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the use of this New Enhanced for loop feature ??" Watch "What is the use of this New Enhanced for loop feature ??" New topic
Author

What is the use of this New Enhanced for loop feature ??

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi all ,

I am trying to uunderstand the New For loop Enhanced Feature .

I have written this sample Example for my understanding purpose .



This works fine .
Could anybody tell me , with this new Enhanced feature will the performance would be increased ??
Or What is the use of this New Enhanced for loop feature ?? Please guide me , Thanks .


Save India From Corruption - Anna Hazare.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9962
    
163

http://download.oracle.com/javase/1.5.0/docs/guide/language/foreach.html

[My Blog] [JavaRanch Journal]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Ravi Kiran Va wrote:This works fine .

Try again with a LinkedList with several thousands of objects. See how well it performs.

Here's a little test program for you:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The main advantage is that it makes your source code simpler and easier to read. Using the new enhanced for loop does not automatically increase performance.

By the way, it isn't really that new anymore, it was introduced in Java 5 which was released in September 2004, more than six years ago...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you very much Rob Prime and Jesper de Jong , as usual you rock .
Anyways ,I know that , Posting a question in this Category (Java in General or Java Beginer ) will yield me prompt results
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the use of this New Enhanced for loop feature ??
 
Similar Threads
for loop and the list iterator
new for loop syntax
Doubt i a generics question
ArrayList with Iterator new*
Can an arraylist hold null reference or not using add(Index i, Object obj) method?