It's not a secret anymore!
The moose likes Beginning Java and the fly likes Enhanced for loop in Java5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enhanced for loop in Java5" Watch "Enhanced for loop in Java5" New topic

Enhanced for loop in Java5

niranjan karkera

Joined: Feb 06, 2008
Posts: 1
for(int e: a[])
//print the value of e

is there any approach to get the index value of array
(eg: in the earlier version of for loop we could retrieve the index i value)
Sheikh Sadiruddin

Joined: Aug 10, 2007
Posts: 21

SCJP 6 (80%) || SCWCD 5 (92%)
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
If you need the index, just use the old for loop.
It is sorta covered in the JavaRanch Style Guide.
subject: Enhanced for loop in Java5
It's not a secret anymore!