title: How do I print out all keys in hashmap?
body: <p>I'm trying to learn how hashmaps work and I've been fiddling with a small phonebook program.</p>
  
  <p>But I'm stumped at what to do when I want to print out all the keys.</p>
  
  <p>here's my code:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.*;
  
  public class MapTester
  {
  
  private HashMap&lt;String, String&gt; phoneBook;
  
  public MapTester(){
     phoneBook = new HashMap&lt;String, String&gt;();
  }
  
  public void enterNumber(String name, String number){
     phoneBook.put(name, number);
  }
  
  public void printAll(){
      //This is where I want to print all. I've been trying with iterator and foreach, but I can't get em to work
  }
  
     public void lookUpNumber(String name){
      System.out.println(phoneBook.get(name));
  }
  }
  </code></pre>