java - Writing to an Excel file using Apache POI a huge data from ArrayList of Strings -


i have arraylist of strings quite huge(approximately on 500k , more of items). there possibility speed writing array excel file? right takes while , have no idea if did could(maybe problem .get method?). please refer following code(please not pay attation details- class created test purposes):

import java.io.file; import java.io.fileoutputstream; import java.io.ioexception; import java.util.arraylist; import java.util.list; import org.apache.poi.ss.usermodel.cell; import org.apache.poi.ss.usermodel.row; import org.apache.poi.ss.usermodel.sheet; import org.apache.poi.ss.usermodel.workbook; import org.apache.poi.xssf.usermodel.xssfworkbook;  public class tests {  private static final string address = "./result/file.xlsx";  public static void readandwriteadata(int counterofexecutions, list<string> listofresults) throws ioexception{      file file = new file(address);     if(file.exists()&&!file.isdirectory()){         file.delete();     }      @suppresswarnings("resource")     workbook wb = new xssfworkbook();      fileoutputstream fileout = new fileoutputstream(address);     wb.write(fileout);     fileout.close();      sheet sheet = wb.createsheet("1");     row row;     cell cell;     int add = 0;     system.out.println("start of filling excel file");      for(int i=0; i<counterofexecutions;i++){         row = sheet.createrow(i);          for(int j=0; j<5; j++){             cell = row.createcell(j);             cell.setcellvalue(listofresults.get(j+add));         }          add+=5;     }       fileoutputstream fileoutputsecond = new fileoutputstream(file);     wb.write(fileoutputsecond);     fileoutputsecond.close();     system.out.println("file "+address+" has been created."); }  public static void main(string[] args) throws ioexception {      system.out.println("start of creating arraylist");     list<string> lista = new arraylist<>();     for(int = 1 ; i<550000;i++){         lista.add("nic "+i);     }     system.out.println("arraylist has been filled");       readandwriteadata(100999, lista);     system.out.println("the end");  }  } 

thanks lot in advance hints! :)

please try use sxssfworkbook. more efficient better usage of try see apache poi 3.8 api


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -