What is the most efficient way to convert data from nested lists to an object array (which can be used i.e. as data for JTable)?
List<List> table = new ArrayList<List>(); for (DATAROW rowData : entries) { List<String> row = new ArrayList<String>(); for (String col : rowData.getDataColumn()) row.add(col); table.add(row); } // I'm doing the conversion manually now, but // I hope that there are better ways to achieve the same Object[][] finalData = new String[table.size()][max]; for (int i = 0; i < table.size(); i++) { List<String> row = table.get(i); for (int j = 0; j < row.size(); j++) finalData[i][j] = row.get(j); }
Many thanks!
I don’t know anything about JTable, but converting a list of lists to array can be done with a few lines.