加強for循環(foreach)java
java8代碼示例code
public class Foreach { public static void main(String[] args) { int[] arr=new int[]{1,2,3,4,5}; for(int index=0;index<arr.length;index++){ System.out.println(arr[index]); } System.out.println("~~~~~~~~~~~~~~~~"); for(int i:arr){ System.out.println(i); } System.out.println("~~~~~~~~~~~~~~~~"); for(int j:arr){ System.out.println(arr[j-1]); } } }
java8代碼示例運行結果for循環
1 2 3 4 5 ~~~~~~~~~~~~~~~~ 1 2 3 4 5 ~~~~~~~~~~~~~~~~ 1 2 3 4 5