title: Iterating over sets of numbers
body: <p>I have 3 different sets of numbers, for example<br>
  a={1,3,4}<br>
  b={2,6}<br>
  c={0}  </p>
  
  <p>the size of sets can be variable, e.g. one set with 5 elements, another with 3, etc.</p>
  
  <p>I have saved these values in a hashmap in java,</p>
  
  <pre><code>HashMap H=new HashMap&lt;String,HashSet&lt;Integer&gt;&gt;();
  </code></pre>
  
  <p>for this example, the keys of H are "a","b",and "c".</p>
  
  <p>I want to make all possible combinations of the numbers in these three sets, that is:<br>
  1,2,0<br>
  1,6,0<br>
  3,2,0<br>
  3,6,0<br>
  4,2,0<br>
  4,6,0  </p>
  
  <p>But I have a problem. The number of sets can also be variable, i.e. my HashMap can have 3 to 10 keys. Do you have any idea how I should iterate over the hashmap, so that I can make all possible combinations?</p>
  
  <p>ANSWER:
  I changed the HashMap to Vector, however, it also works with HashMap with little changes  </p>
  
  <p>call the function as follow:  </p>
  
  <pre><code>Iterate_over_map(0,new Integer[h.size()],h,final_list);
  
  
  Iterate_over_map(int count,Integer[] curr,Vector&lt;HashSet&lt;Integer&gt;&gt; h,Vector&lt;Integer[]&gt; final_list)
  {
      if(count&gt;=h.size())
      {
          final_list.addElement(curr.clone());
          return;
      }
  
      int next_count=count+1;
      for (Integer element:h.elementAt(count))
      {
  
          curr[count]=element;
          Iterate_over_map(next_count,curr,h,final_list);
      }
  
  }
  </code></pre>
  
  <p>OLD solution</p>
  
  <pre><code>for(int x:H.get("a"))
  {
      v[0]=x;//node1 (an ortholog of node1)
      for(int y:H.get("b"))
      {
          v[1]=y;//node2 (an ortholog of node2)
          for(int z:H.get("c"))
          {
              v[2]=z;//node3 (an ortholog of node3)
          }
      }
  }
  </code></pre>
  
  <p>thanks a lot.</p>