• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enhanced for loops

 
Faisal A Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the K&B book, Enhanced for loops are said to be new to Java 6.

But this was introduced in Java 5 wasn't it? What was using in Java 5?

Can you please either correct me or explain?

Regards
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
enhanced for loop was introduced in java 6 to specifically iterate over arrays and collections .Before that and even in java 5.0 we used basic for loop .
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faisal A Khan wrote:In the K&B book, Enhanced for loops are said to be new to Java 6.

But this was introduced in Java 5 wasn't it? What was using in Java 5?

Can you please either correct me or explain?

Regards


The foreach loop was introduced in java 5, as documented here -> http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/guide/language/foreach.html
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enhance for loop is introduced in java 5, check it here
 
mahesh shinde
Ranch Hand
Posts: 69
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its true Enhanced for loop is introduced in java1.5.
 
Harshit Sethi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this is an error in kathy sierra.Good work.
 
Faisal A Khan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshit Sethi wrote:enhanced for loop was introduced in java 6 to specifically iterate over arrays and collections .Before that and even in java 5.0 we used basic for loop .


I have used enhanced for loops in Java 5. Refer to http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#forloop

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic