Two dimensional array with different lengths (Java)

前端 未结 2 1386
清酒与你
清酒与你 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 08:48

    Java does not have 2-dimensional arrays.

    Java has 1-dimensional arrays whose elements can be any primitive or reference type - including other arrays.

    0 讨论(0)
  • 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};
    
    0 讨论(0)
提交回复
热议问题