Studyon Minte9.com
Java SE




Loop




package testexample; public class Testexample { public static void main(String[] args) { for (int i=0; i<3; i++) { System.out.println(i); } // Outputs: 012 } }
  Multidimensional
package testexample; public class Testexample { public static void main(String[] args) { String[][] data = new String[][] { {"1","a"}, {"2","b","c"}, }; for (int i=0; i<data.length; i++) { for (int j=0; j<data[i].length; j++) { System.out.println(i + "" + j + ":" + data[i][j]); } } // Outputs: 00:1 , 01:a , 10:2 , 11:b , 12:c } }
  Multidimensional List
package testexample; import java.util.ArrayList; import java.util.Collections; public class Testexample { public static void main(String[] args) { String[][] ss = { {"1","a"}, {"2","b","c"} }; ArrayList<String[]> sss = new ArrayList<String[]>(); Collections.addAll(sss, ss); for (String[] v : sss) { System.out.print("ss[" + sss.indexOf(v) + "] = "); for (String vv : v) { System.out.print(vv + ", "); } System.out.println(""); } // Outputs: ss[0] = 1, a / ss[1] = 2, b, c } }
 


http://stackoverflow.com/questions/3431529/java-how-do-i-get-current-index-key-in-for-each-loop