0

I'm trying to create a 2D array in Java with the use of IntelliJ.

The statement in particular is board = new Cell[size][size]. When debugging I detect that, after the statement, IntelliJ creates a 1D Cell[size][] array. IntelliJ has ignored the array's second dimension for some reason.

Does someone know what could be happening?

Thanks a lot in advance.

  • 1
    There are no actual "2D arrays" in Java. Your code creates a 1D array whose elements are 1D arrays of Cells. – Olivier Jun 12 '22 at 10:53
  • Hi Olivier, thank you for your response. 2 or more dimensional arrays do exist in Java: https://www.geeksforgeeks.org/multidimensional-arrays-in-java/ – The_Student Jun 12 '22 at 11:13
  • 1
    Internally they are not true 2D arrays. See [this](https://stackoverflow.com/questions/12231453/syntax-for-creating-a-two-dimensional-array-in-java). – Olivier Jun 12 '22 at 11:56
  • Exactly @Olivier, multidimensional arrays in Java aren't like that, they're just arrays of arrays. IntelliJ represents them like unidimensional in debugging. Thank you a lot for your answer. – The_Student Jun 12 '22 at 12:26

0 Answers0