title: How to convert csv to a map using Java 8 Stream
body: <p>I'm trying to create a simple parsing util that converts a two-column CSV file and put it into a map. </p>
  
  <pre><code>public Map&lt;String, String&gt; getMapFromCSV(final String filePath) throws IOException {
      return Files.lines(Paths.get(filePath))
                  .map(line -&gt; line.split(","))
                  .collect(Collectors.toMap(line -&gt; line[0], line -&gt; line[1]));
  }
  </code></pre>
  
  <p>As you can see, I'm creating a stream of strings, delimiting each line on a comma and transforming it into a string array, and finally mapping key to index 0 and value to index 1. </p>
  
  <pre><code>@Test
  public void testGetMapFromCSV() throws IOException{
      actual = util.getMapFromCSV(filePath).get("AL");
      expected = "ALABAMA";
  
      assertEquals(expected, actual);
  }
  </code></pre>
  
  <p>For some reason, when I run this test, the actual value is null. I ruled out invalid filePath because it's working fine in another unit test, and the key value is present in the CSV. I've been staring at it for a few hours now, figured maybe someone here could point out my error. </p>
  
  <p>Also, I'm fairly new to Java 8, so if anyone knows a better/cleaner way of writing this, I'd appreciate the feedback.</p>