IndexOutOfBoundsException when i write excel document using list of string : <p>i have 2 ArrayList of string and i want to copy their content in an excel document. I am using HSSF class to make this and if i create statically the document it works perfectly, but when i use a for loop to copy arraylist content i get <code>IndexOutOfBoundsException</code> exception</p>

<p>Here the code:</p>

<pre><code>import java.io.FileOutputStream;
import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class createExcel {

    public void write(ArrayList&lt;String&gt; FirstList, ArrayList&lt;String&gt; SecondList) {
        try {
            String filename = "mypath\\file.xlsx" ;
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("Report");

            for(int i=0; i&lt;FirstList.size()+SecondList.size(); i++) {
                HSSFRow row = sheet.createRow((short)i);
                row.createCell(0).setCellValue(FirstList.get(i));
                row.createCell(1).setCellValue(SecondList.get(i));
            }

            FileOutputStream fileOut = new FileOutputStream(filename);
            workbook.write(fileOut);
            fileOut.close();
            System.out.println("Your excel file has been generated!");

        } catch ( Exception ex ) {
            System.out.println(ex);
        }
    }
}
</code></pre>

<p>Thanks</p>
