Arrayofarrays/arrayofobjects/arrayListofarrayList'如何表示多维数组或对象集合
创始人
2024-11-10 15:01:09
0次
- 数组的数组:可以使用二维数组来表示,例如 int[][] arr = new int[3][4]; 表示一个 3 行 4 列的二维数组,也可以使用不规则数组,例如 int[][] arr = new int[3][]; arr[0] = new int[2]; arr[1] = new int[3]; arr[2] = new int[4]; 表示一个 3 行,分别有 2、3、4 列的不规则数组。
- 对象的数组:可以使用类来表示,例如定义一个 Student 类,使用 Student[] students = new Student[5]; 来创建一个装有 5 个 Student 对象的数组。
- ArrayList 的 ArrayList:可以使用嵌套 ArrayList 的方式来表示,例如 ArrayList> list = new ArrayList>(); 来表示一个装有多个 ArrayList 对象的 ArrayList。
相关内容