title: Removing several blank lines in XLS using Apache POI HSSF with an incrementing loop
body: <p>I need to remove several lines of an excel xls sheet.
  These lines always contain the same first cell thats why i check the first cell of all rows to find these rows</p>
  
  <pre><code>SSFCell myCell = myRow.getCell(0);
              myCell.setCellType(Cell.CELL_TYPE_STRING);
              String foundString = myCell.getStringCellValue();
              if(foundString.equals(searchString)){
                  foundRows.add(rowCount);
              }
              rowCount++;
  </code></pre>
  
  <p>I then go on and "remove" those rows using removeRow which nulls all values</p>
  
  <pre><code>public static void removeRows() {
  
      List&lt;Integer&gt; foundRowsToDelete = new ArrayList&lt;Integer&gt;();
      //Copy values to another list
      for(int i=0; i&lt;foundRows.size(); i++){
          foundRowsToDelete.add(foundRows.get(i));
      }
      //Delete values from rows, leaving empty rows
      while(foundRowsToDelete.size()!=0){
          int rowIndex = foundRowsToDelete.get(0);
          Row removingRow = mySheet.getRow(rowIndex);
          if (removingRow != null) {
              mySheet.removeRow(removingRow);
              foundRowsToDelete.remove(0);
      }
  }
      //Move empty rows to bottom of the sheet
      for(int i = 0; i &lt; mySheet.getLastRowNum(); i++){
          if(isRowEmpty(i)){
              mySheet.shiftRows(i+1, mySheet.getLastRowNum(), -1);
              i--;
          }
      }
  }
  </code></pre>
  
  <p>I check if they are empty through using the duplicated rowcounter</p>
  
  <pre><code>//Comparision of previously detected empty rows and given row count
  public static boolean isRowEmpty(int suspectedRowNumber) {
      for(int i=0;i&lt;foundRows.size();i++){
          if (suspectedRowNumber == foundRows.get(i)){
              foundRows.remove(i);
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>However only the first of these rows gets deleted. The rest will stay empty.
  I therefore assume that there is something wrong with some incrementing done by me, but i just can't figure out exactly why.</p>
  
  <p>Thanks for your help in advance.</p>