Declare Multiple Java Arrays on Same Line?

前端 未结 4 1771
無奈伤痛
無奈伤痛 2020-12-03 22:55

Is it possible to initialize and/or declare multiple arrays in the same line in Java?

ie.

int a, b, c, d, e = 4

works but

4条回答
  •  粉色の甜心
    2020-12-03 23:20

    What you tried is possible only for value types. In Java arrays are reference types i.e. objects.

    What you tried is not possible (as Gwyn explained).

    On the other hand you could:

    int[][] arrays = new int[4][5];
    

    And then use: arrays[0], arrays[1].. instead od a,b.

提交回复
热议问题