title: JAVA: maps and return type of Map.get
body: <p>I have a hashmap of key and value both of String type. </p>
  
  <pre><code>Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
  //put the key-values now
  </code></pre>
  
  <p>I want to check for null or emptiness of the value of a particular key. Referencing the discussion <a href="https://stackoverflow.com/questions/3321526/should-i-use-string-isempty-or-equalsstring"> here</a>, I do it as:</p>
  
  <pre><code>if("".equals(map.get("keyName")) {
      //do stuff
  }
  </code></pre>
  
  <p>Is it valid?
  As the return type of Map.get is Object, so do I need to check it like this:</p>
  
  <pre><code>if("".equals(map.get("keyName").toString()) {
      //do stuff
  }
  </code></pre>
  
  <p>But toString() gives null pointer exception if it is null. So, what is the right way to do it?
  Yes, I'm a beginner.</p>