title: Retrieving hashmap values in java
body: <p>I wrote below code to retrieve values in hashmap. But it didnt work.</p>
  
  <pre><code>HashMap&lt;String, String&gt; facilities = new HashMap&lt;String, String&gt;();
  
  Iterator i = facilities.entrySet().iterator();
  
  while(i.hasNext())
  {
      String key = i.next().toString();  
      String value = i.next().toString();
      System.out.println(key + " " + value);
  }
  </code></pre>
  
  <p>I modified the code to include SET class and it worked fine.</p>
  
  <pre><code>Set s= facilities.entrySet();
  Iterator it = facilities.entrySet().iterator();
  while(it.hasNext())
  {
      System.out.println(it.next());
  }
  </code></pre>
  
  <p>Can anyone guide me what went wrong in above code without SET class??</p>
  
  <p>P.S - I do not have much programming exp and started using java recently</p>