title: I am trying to match first row of one sheet against first row of another sheet and retrieving matching data
body: <p>I am trying to match the first row of one sheet with the first row of another sheet and retrieve the rest of the data of another sheet</p>
  <p>I have stored the data of the first row in the list like this</p>
  <pre><code>    int rowCount=sheet.getPhysicalNumberOfRows();
      List&lt;String&gt; li=new ArrayList&lt;String&gt;();
      for (int x=0; x&lt;rowCount; x++) {
          li.add(sheet.getRow(x).getCell(0).getStringCellValue());
      }
  </code></pre>
  <p>However, the below code is not able to compare the data of the first row with the data of the first row of another sheet</p>
  <pre><code>    sheet=workbook.getSheetAt(1);
      rowCount=sheet.getPhysicalNumberOfRows();
      for (int x=0; x&lt;rowCount; x++) {
          System.out.println(sheet.getRow(x).getCell(0).getStringCellValue());//------------
          if (li.get(x).equalsIgnoreCase(sheet.getRow(x).getCell(0).getStringCellValue())) {
              //retrieve the data of matching row
          }
  </code></pre>
  <p>Please help here</p>
  <p>Edit: I have managed to achieve but I am getting NullPointerException</p>
  <pre><code>    for (int y=0; y&lt;rowCount; y++) {
              System.out.println(li.get(y));
              for (int z=0; z&lt;rowCount; z++) {
                  if (li.get(y).equalsIgnoreCase(sheet.getRow(z).getCell(0).getStringCellValue())) {
                      XSSFRow row=sheet.getRow(z);
                      for (int x=1; x&lt;=row.getLastCellNum(); x++) {
                          System.out.println(row.getCell(x).getStringCellValue());
                          System.out.println(&quot;found&quot;);
  //                      break;
                      }
                  }
  
              }
          }
  </code></pre>