title: Parsing a CSV file for a unique row using the new Java 8 Streams API
body: <p>I am trying to use the new Java 8 Streams API (for which I am a complete newbie) to parse for a particular row (the one with 'Neda' in the name column) in a CSV file.  Using the following <a href="http://blog.codeleak.pl/2014/05/parsing-file-with-stream-api-in-java-8.html" rel="noreferrer">article</a> for motivation, I modified and fixed some errors so that I could parse the file containing 3 columns - 'name', 'age' and 'height'.</p>
  
  <pre><code>name,age,height
  Marianne,12,61
  Julie,13,73
  Neda,14,66
  Julia,15,62
  Maryam,18,70
  </code></pre>
  
  <p>The parsing code is as follows:</p>
  
  <pre><code>@Override
  public void init() throws Exception {
      Map&lt;String, String&gt; params = getParameters().getNamed();
      if (params.containsKey("csvfile")) {
          Path path = Paths.get(params.get("csvfile"));
          if (Files.exists(path)){
              // use the new java 8 streams api to read the CSV column headings
              Stream&lt;String&gt; lines = Files.lines(path);
              List&lt;String&gt; columns = lines
                  .findFirst()
                  .map((line) -&gt; Arrays.asList(line.split(",")))
                  .get();
              columns.forEach((l)-&gt;System.out.println(l));
              // find the relevant sections from the CSV file
              // we are only interested in the row with Neda's name
              int nameIndex = columns.indexOf("name");
              int ageIndex columns.indexOf("age");
              int heightIndex = columns.indexOf("height");
              // we need to know the index positions of the 
              // have to re-read the csv file to extract the values
              lines = Files.lines(path);
              List&lt;List&lt;String&gt;&gt; values = lines
                  .skip(1)
                  .map((line) -&gt; Arrays.asList(line.split(",")))
                  .collect(Collectors.toList());
              values.forEach((l)-&gt;System.out.println(l));
          }
      }        
  }
  </code></pre>
  
  <p>Is there any way to avoid re-reading the file following the    extraction of the header line?  Although this is a very small example    file, I will be applying this logic to a large CSV file. </p>
  
  <p>Is there technique to use the streams API to create a map between the extracted column names (in the first scan of the file) to the values in the remaining rows?</p>
  
  <p>How can I return just one row in the form of <code>List&lt;String&gt;</code> (instead of <code>List&lt;List&lt;String&gt;&gt;</code> containing all the rows).  I would prefer to just find the row as a mapping between the column names and their corresponding values.  (a bit like a result set in JDBC).  I see a Collectors.mapMerger function that might be helpful here, but I have no idea how to use it.</p>