创建数组的两种方式,动态初始化和静态初始化

  • Post author:
  • Post category:其他


 1 package com.pang.array_demo;
 2 
 3 import java.util.Arrays;
 4 
 5 //创建数组的两种形式
 6 public class New_Array {
 7     public static void main(String[] args) {
 8         // 动态初始化
 9         int[] arr = new int[4];
10         arr[0] = 1;
11         arr[1] = 2;
12         arr[2] = 4;
13         arr[3] = 5;
14 
15         System.out.println(Arrays.toString(arr));
16         // 静态初始化
17         int[] arr1 = { 2, 3, 4, 5 };
18         System.out.println(Arrays.toString(arr1));
19     }
20 }

转载于:https://www.cnblogs.com/pangguobo/p/7028254.html