Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

foreach equivalent in java

Status
Not open for further replies.

Umamageswari

Programmer
Mar 18, 2003
7
IN
Hi all,

I am doing some conversion process from C# to java. I am struck with c# foreach statement.

Here I give the coding,
foreach (MapFieldInfo item in Fields)
{
if (item == null)
{
continue;
}
if (item.Field.Equals(fieldInfo))
{
exp = item.NewExpression;
break;
}
}

Here the MapFieldInfo in another class. I need the equivalent java for loop for this statement.

Pls could anyone help me.

Thanks in advance.
Uma
 
Look up the Enumerator class, from memory.

codestorm
Newbie Life Member.
Fire bad. Tree pretty. - Buffy
<insert witticism here>
 
Also another option is to use a for loop...Something like:

Code:
for (int i = 0; i < myArray.length; i++)

Also if the fields are coming from a JSP page, Apache's TagLib defines a standard
Code:
foreach
tag.

Just as a FYI...in the J2SE 1.5 release there is an enhancement to the for loop, to act just like the forEach statement, to read more about that you can check out the following article:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top