java数组三种初始化方式

	public static void main(String[] args) {
        //第一种数组初始化
        Integer[] ints1 = {1,2,3};
        //第二种数组初始化
        Integer[] ints2 = new Integer[]{4,5,6};
        //第三种数组初始化
        Integer[] ints3 = new Integer[3];
        for (int i = 0; i < ints3.length; i++) {
            ints3[i] = i+7;
        }
        //结果
        System.out.println(Arrays.toString(ints1));//output:[1, 2, 3]
        System.out.println(Arrays.toString(ints2));//output:[4, 5, 6]
        System.out.println(Arrays.toString(ints3));//output:[7, 8, 9]
    }

 

posted @ 2022-06-01 09:20  锐洋智能  阅读(608)  评论(0编辑  收藏  举报