Explicitly assigning values to a 2D Array?

后端 未结 6 667
遇见更好的自我
遇见更好的自我 2020-12-11 00:58

I\'ve never done this before and can\'t find the answer. This may not be the correct data type to use for this, but I just want to assign an int, then another int without a

6条回答
  •  萌比男神i
    2020-12-11 01:30

    Are you looking to assign all values in a 2D array at declaration time? If so, it works as follows:

    int[][] contents = new int[][]{ {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    

    Remember that a 2D array in Java is really an array of arrays, but Java gives you some special syntax if you do this at declaration time.

提交回复
热议问题