在数组中,我们可以初始化如下内容:
int[] arr = {1, 2, 3, 4, 5};
但是对于二维数组,为什么下面不正确?
public class Main { public static void main(String[] args) { int[][] arr = new int[3][]; arr[0] = new int[]{1,2,3}; //This is the correct way arr[0] = {1,2,3}; // ->Why this is not right? } }
最佳答案
Yes, you are correct the second way of creating a 2D array will not work because when the compiler will compile the code because it couldn't decide its type.
关于java - 在 Java 中初始化二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51122798/