How can I improve the performance of this double-for print?
Posted
by
Florenc
on Stack Overflow
See other posts from Stack Overflow
or by Florenc
Published on 2012-06-18T21:13:38Z
Indexed on
2012/06/18
21:16 UTC
Read the original article
Hit count: 275
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...
© Stack Overflow or respective owner