title: Java HashMap returning null values even when key is present
body: <p>I am working on a project in which we insert key and value pairs in a <code>Map</code>. </p>
  
  <p>If the key is present in the <code>Map</code>, my code returns the value for that key. </p>
  
  <p>However, the <code>HashMap</code> is not returning the expected values, even though the key is present.</p>
  
  <p>First I read the key and value pairs from a file, then I read another file which has almost the same keys as the first file.</p>
  
  <p>Then I return values for some keys, but for many of them the value is <code>null</code>.</p>
  
  <p>Here is a snippet of my code: </p>
  
  <pre><code>Scanner scanner = new Scanner(new FileReader("a.txt"));
  
  LinkedHashMap&lt;String, String&gt; map = new LinkedHashMap&lt;String, String&gt;();
  
  while (scanner.hasNextLine())
  {
     String[] columns = scanner.nextLine().split(";");
     map.put(columns[0], columns[1]);
  }
  
  System.out.println(map);
  
  for (Map.Entry&lt;String, String&gt; entry : map.entrySet())
  { // name is the input of second file
      if (entry.getKey().equals(name)) 
      {
          num = entry.getValue();         
          fun(num);
      }
  }
  </code></pre>
  
  <p>My input file is</p>
  
  <p>abc;1</p>
  
  <p>def;2</p>
  
  <p>ghi;3</p>
  
  <p>...
  and name will be
  abc</p>
  
  <p>def</p>