title: Java 8 toMap IllegalStateException Duplicate Key
body: <p>I have a file which contains data in the following format</p>
  
  <pre><code>1
  2
  3
  </code></pre>
  
  <p>I want to load this to map as <code>{(1-&gt;1), (2-&gt;1), (3-&gt;1)}</code></p>
  
  <p>This is the Java 8 code,         </p>
  
  <pre><code>Map&lt;Integer, Integer&gt; map1 = Files.lines(Paths.get(inputFile))
                  .map(line -&gt; line.trim())
                  .map(Integer::valueOf)
                  .collect(Collectors.toMap(x -&gt; x, x -&gt; 1));
  </code></pre>
  
  <p>I am getting the following error </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: Duplicate key 1
  </code></pre>
  
  <p>How do I fix this error?</p>