foreach 语法糖

x33g5p2x  于2022-05-05 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(383)
// 源码
public class Test {
    public static void test1() {
        int[] arr = {1, 2, 3, 4, 5};
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void main(String[] args) {
        test1();
    }
}
// 反编译
public class Test {
    public Test() {
    }

    public static void test1() {
        int[] arr = new int[]{1, 2, 3, 4, 5};
        int[] var1 = arr;
        int var2 = arr.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            int i = var1[var3];
            System.out.println(i);
        }

    }

    public static void main(String[] args) {
        test1();
    }
}
// 源码
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void test1() {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        for (Integer integer : list) {
            System.out.println(integer);
        }
    }

    public static void main(String[] args) {
        test1();
    }
}
// 反编译
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
    public Test() {
    }

    public static void test1() {
        List<Integer> list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        Iterator var1 = list.iterator();

        while(var1.hasNext()) {
            Integer integer = (Integer)var1.next();
            System.out.println(integer);
        }

    }

    public static void main(String[] args) {
        test1();
    }
}

创作打卡挑战赛

赢取流量/现金/CSDN周边激励大奖

相关文章