What does the statement Object[][] data = new Object [][] mean?

In this statement

Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];

It is creating an array of references to arrays of references to Objects. The first array is for rows and the leaf arrays are for column values.

In reality, only String objects are added so I would write it like this.

int rows = sheet.getLastRowNum();
int columns = sheet.getRow(0).getLastCellNum();
String[][] data = new String[rows][columns];

If you want to see how this looks at runtime, I suggest stepping through the code in your debugger.

Leave a Comment