title: To skip empty records from a CSV file using Apache Commons CSV
body: <p>if a CSV file contains three columns and if the values are as given below</p>
  
  <pre><code>a,b,c
       //empty line
  ,,,
  a,b,c
  </code></pre>
  
  <p>There are two valid records. Using Apache commons CSV parser, i could easily skip the record which has empty lines. But when the records contain only null values, how to skip it then?</p>
  
  <p>To overcome this, I'm using <code>String</code> <code>equals()</code> with already constructed empty record. Here is a sample implementation.</p>
  
  <pre><code>List&lt;String[]&gt; csvContentsList = new ArrayList&lt;String[]&gt;();
  CSVFormat csvFormat = CSVFormat.DEFAULT.withNullString("");
  CSVParser csvParser = new CSVParser(fileReader, csvFormat);
  
  String[] nullRecordArray = { null, null, null};
  String nullRecordString = Arrays.toString(nullRecordArray);
  for (CSVRecord csvRecord : csvParser) {
      try {
          String values[] = { csvRecord.get(0),csvRecord.get(1),csvRecord.get(2) };
          if (!nullRecordString.equals(Arrays.toString(values))) //lineA
              csvContentsList.add(values);
      } catch (Exception e) {
          // exception handling
      }
  }
  </code></pre>
  
  <p>When i don't use the line marked as 'lineA', this implementation gives three records in the <code>csvContentsList</code> as below</p>
  
  <pre><code>[a,b,c]
  [null,null,null]
  [a,b,c]
  </code></pre>
  
  <p>Is there any inbuilt way to do this? or any other better way?</p>