How can I improve the performance of this double-for print?
- by Florenc
I have the following static method that prints the data imported from a 40.000 lines .xls spreadsheet.
Now, it takes about 27 seconds to print the data in the console and the memory consumption is huge.
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
public static void printSheetData(List<List<HSSFCell>> sheetData) {
for (int i = 0; i < sheetData.size(); i++) {
List<HSSFCell> list = (List<HSSFCell>) sheetData.get(i);
for (int j = 0; j < list.size(); j++) {
HSSFCell cell = (HSSFCell) list.get(j);
System.out.print(cell.toString());
if (j < list.size() - 1) {
System.out.print(", ");
}
}
System.out.println("");
}
}
Disclaimer: I know, I know large data belong to a database, don't print output in the console, premature optimization is the root of all evils...