title: Iterating over hashmap
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/46898/how-do-i-iterate-over-each-entry-in-a-map">How do I iterate over each Entry in a Map?</a><br>
    <a href="https://stackoverflow.com/questions/3995463/how-can-i-iterate-over-a-map-of-string-pojo">How can I iterate over a map of &lt;String, POJO&gt;?</a>  </p>
  </blockquote>
  
  
  
  <p>I've written the following piece of code and am stuck on iterating over the hashmap.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  
  class demo
  {
      public static void main(String v[]) {
          ArrayList&lt;String&gt; contactIds = new ArrayList&lt;String&gt;();
          contactIds.add("2");
          contactIds.add("3");
  
          HashMap names = new HashMap();
          names =  getNames(contactIds);
  
          // I want to get the total size of the hashmap  - names
          // for ex now there are 6 elements inside hashmap.
          // How can I get that count?
  
      }
  
  
      private static HashMap getNames(ArrayList contactIds) {
          HashMap names = new HashMap();
          String params = null;
          List&lt;String&gt; list = new ArrayList&lt;String&gt;();
          for(int i=0; i&lt;contactIds.size();i++) {
              params = contactIds.get(i).toString();
  
              list.add(0,"aer-1");
              list.add(1,"aer-2");
              list.add(2,"aer-3");
  
              names.put(params,list) ;
           }
  
          return names;
      }
  }
  </code></pre>
  
  <p>In this code, there are six elments inside the map, now in the main method how can I iterate over the map and get the total count?</p>
  
  <p>Thank you.</p>