Declare Multiple Java Arrays on Same Line?

前端 未结 4 1781
無奈伤痛
無奈伤痛 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:19

    try

    int[] a = new int[4], b = new int[4], c = new int[4], d = new int[4], e = new int[4];

    You have to instantiate an array for each variable if you want to create five different arrays.

    If you want to create one array and reference it from five variables Goran has the solution.

提交回复
热议问题