title: Parsing entire csv file vs parsing line by line in java
body: <p>I have somewhat of a larger csv file approximately 80K to 120K rows (depending on the day). I'm successfully running the code which parses the entire csv file into a java object using <code>@CsvBindByName</code> annotation. Sample code:  </p>
  
  <pre><code>Reader reader = Files.newBufferedReader(Paths.get(file));
      CsvToBean csvToBean = new CsvToBeanBuilder&lt;Object&gt;(reader)
              .withType(MyCustomClass.class)
              .withIgnoreLeadingWhiteSpace(true)
              .build(); 
      List&lt;MyCustomClass&gt; myCustomClass= csvToBean.parse();`
  </code></pre>
  
  <p>I want to change this code to parse the csv file line by line instead of entire file but retain the neatness of mapping to java bean object. Essentially something like this: </p>
  
  <pre><code>    CSVReader csvReader = new CSVReader(Files.newBufferedReader(Paths.get(csvFileLoc)));
      String[] headerRow = csvReader.readNext(); // save the headerRow
      String [] nextLine = null;
      MyCustomClass myCustomClass = new MyCustomClass(); 
      while ((nextLine = csvReader.readNext())!=null) {
                      myCustomClass.setField1(nextLine[0]);
                      myCustomClass.setField2(nextLine[1]);
                      //.... so on 
                  }
  </code></pre>
  
  <p>But the above solution ties me to knowing the column positions for each field. What I would like is to map the string array I get from csv based on the header row similar to what opencsv does while parsing the entire csv file. However, I am not able to do that using opencsv, as far as I can tell. I had assumed this would be a pretty common practice but I am unable to find any references to this online. It could be that I am not understanding the <code>CsvToBean</code> usage correctly for opencsv library. I could use <code>csvToBean.iterator</code> to iterate over the beans but I think entire csv file is loaded in memory with the <code>build</code> method, which kind of defeats the purpose of reading line by line. Any suggestions welcome</p>