Two dimensional array with different lengths (Java)

前端 未结 2 1387
清酒与你
清酒与你 2021-01-23 08:34

Is there an opportunity to create two dimensional Arrays with different lengths in the second dimension? For example like this:

[true] [true] [true]

[true]

2条回答
  •  抹茶落季
    2021-01-23 09:03

    Yes, arrays in a 2D array don't have the have same size. E.g.:

    boolean[][] twoDimensionalArray = new boolean[3][];
    twoDimensionalArray[0] = new boolean[]{true, true, true};
    twoDimensionalArray[1] = new boolean[]{true};
    twoDimensionalArray[2] = new boolean[]{true, true, true, true, true};
    

提交回复
热议问题