title: Using HashMap values of HashSet type
body: <p>I have some problem using HashMap values of HashSet type. I declared it as followed:</p>
  
  <pre><code>HashMap&lt;Double, HashSet&lt;Double&gt;&gt; pre = new HashMap&lt;Double, HashSet&lt;Double&gt;&gt;();
  </code></pre>
  
  <p>In my program I am generating pythagorean triples (a, b, c). I want to add b to the HashSet corresponding to the key a and add a to the HashSet corresponding to the key b.
  There are 9 triples with perimeter less than 60:</p>
  
  <pre><code>3 4 5
  6 8 10
  9 12 15
  12 16 20
  15 20 25
  5 12 13
  10 24 26
  7 24 25
  15 8 17
  </code></pre>
  
  <p>So after generating each triple, I have to update the HashSet corresponding to a or b. After completion, the HashMap will look like followd:</p>
  
  <pre><code>1:                14:
  2:                15: 8, 20
  3: 4              16: 12
  4: 3              17:
  5: 12             18:
  6: 8              19:
  7: 24             20: 15
  8: 6, 15          21:
  9: 12             22:
  10: 24            23:
  11:               24: 7, 10
  12: 5, 9, 16      25:
  13:               26:
  </code></pre>
  
  <p>How can I do this? Any help will be appreciated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  import java.math.*;
  
  public class prob {
      public static double P = 60.0;
      public static double primCount = 0.0;
      public static double tripCount = 0.0;
      public static ArrayList&lt;Triple&gt; pt = new ArrayList&lt;Triple&gt;();
      public static HashMap&lt;Double, HashSet&lt;Double&gt;&gt; pre = new HashMap&lt;Double, HashSet&lt;Double&gt;&gt;();
      public static void main(String[] args) {
          double start = System.currentTimeMillis();
          double sum = 0.0;
          for (int i = 0; i &lt; 30; i++) {
              pre.put((double)i, new HashSet&lt;Double&gt;(0));
          }
          p(3.0, 4.0, 5.0);
          for (int i = 0; i &lt; pre.size(); i++) {
              System.out.println(pre.get(i));
          }
          double end = System.currentTimeMillis();
          System.out.println("Time elapsed : " + (end - start) / 1000d + " seconds");
      }
  
      public static void p(double A, double B, double C) {
          double a = A, b = B, c = C;
          if (a + b + c &gt; P) {
              return;
          }
          primCount++;
          double I = Math.floor(P / (a + b + c));
          tripCount += I;
          for (double i = 1; i &lt;= I; i++) {
              pt.add(new Triple(a * i, b * i, c * i));
              HashSet&lt;Double&gt; copya = pre.get(a * i);
              copya.add(b * i);
              pre.remove(a * i);
              pre.put(a * i, copya);
              HashSet&lt;Double&gt; copyb = pre.get(b * i);
              copyb.add(a * i);
              pre.remove(b * i);
              pre.put(b * i, copyb);
          }
          p(a - 2 * b + 2 * c, 2 * a - b + 2 * c, 2 * a - 2 * b + 3 * c);
          p(a + 2 * b + 2 * c, 2 * a + b + 2 * c, 2 * a + 2 * b + 3 * c);
          p(2 * b - a + 2 * c, b - 2 * a + 2 * c, 2 * b - 2 * a + 3 * c);
      }
  }
  </code></pre>