title: How to get cell value without moving iterator forward - Excel, Java POI
body: <p>I have problem with iteration over rows and cells in excel using java. I have data structured in sheet in this way:</p>
  
  <p><a href="https://i.stack.imgur.com/nltq2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nltq2.jpg" alt="enter image description here"></a></p>
  
  <p>I have to collect all the numbers and pass it to the constructor. I tried sth like this:</p>
  
  <pre><code>Iterator&lt;Row&gt; iterator = firstSheet.iterator();
  while (iterator.hasNext()){
           Row nextRow = iterator.next();
           Iterator&lt;Cell&gt; cellIterator = nextRow.cellIterator(); 
           int id = (int) cellIterator.next().getNumericCellValue();
           int pr = (int) cellIterator.next().getNumericCellValue();
           int[] prId = new int[2];
  
           prId[0] = (int) cellIterator.next().getNumericCellValue();
  
           iterator.next(); // i have to move down one row to get 5 and 6
  
           precId[1] = // what should I type here?? cellIterator.next() will cause, that cell with value "5" will be omitted and I will get "6"
           int co = (int) cellIterator.next().getNumericCellValue();
           list.add(new Rule(id, pr, prId, co));
  
      }
  </code></pre>
  
  <p>How to deal with that?
  Thanks in advance :)</p>
  
  <p>EDIT:</p>
  
  <p>I decided to get cells in other way:</p>
  
  <pre><code>for(int rowNum = rowStart+1; rowNum &lt; rowEnd; rowNum++){
          Row r = sheet.getRow(rowNum);
          if(r == null){
              continue;
          }
          int lastColumn = Math.max(r.getLastCellNum(), 4);
          for(int cn = 0; cn &lt; lastColumn; cn++){
              @SuppressWarnings("deprecation")
              Cell c = r.getCell(cn, Row.RETURN_BLANK_AS_NULL);
              if(c == null){
                  continue;
              }else{
                  System.out.println(c);
              }
          }
      }
  </code></pre>
  
  <p>This solution is clearly better but I have problem because instead of show cells value by <code>System.out.println(c)</code> i need to pass this value to the constructor as in the example with iterators. But now i have acces to the cell using loop so i can't get value of next cell using .next() or sth similar - I can't get the next cell in one line of code, so how to create the same object as above (with iterator) but using this code?</p>