Mansueli
Mansueli

Reputation: 7034

Java foreach with subset of multi-variable array

Is it possible in Java to loop in the for each statement to do something similar to this:

for(String path: series[634][][3]){
   //DO Something
}

I want to specify the first and the last part of this multi-variable array and loop through the middle one.

series[const1][loopNo][const2]

Upvotes: 1

Views: 160

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42174

Multi-dimensional arrays are just arrays of arrays. You could do this:

for(String[][] pathArray1 : series[634]){
   for(String[] pathArray2 : pathArray1){
      String path = pathArray2[3];
      //DO something
   }
}

...although this is pretty hackish and ugly, and you should almost definitely use a regular old for loop for this.

Upvotes: 2

Related Questions