Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I use for each for two same sized arrays

Tags:

java

arrays

I have two arrays :

name[] and roll[]

Is there a way to traverse both arrays in one for each loop.Size of both arrays remain the same.

I know using two individual loops we can traverse and infact in one also its not a big deal, but I want something like this:

for(String n:name,int r:roll){
  //blah blah
}

Please shed some light thanks..... Ankur

like image 976
Ankur Verma Avatar asked Jun 29 '12 07:06

Ankur Verma


1 Answers

No. You will have to use the old-fashioned

for(int index = 0; index < name.length; index++) {
  //blah blah with name[index] and roll[index]
}
like image 135
Keppil Avatar answered Oct 13 '22 22:10

Keppil