Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can not reproduce your problem, this is the EXACT code I'm running (not simplified as the other answers to make it as close as possible to your original question).</p> <pre><code>public class HashProblem { public static class Val { private double x; private double y; public Val(double x, double y) { this.x = x; this.y = y; } @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(x); result = prime * result + (int) (temp ^ (temp &gt;&gt;&gt; 32)); temp = Double.doubleToLongBits(y); result = prime * result + (int) (temp ^ (temp &gt;&gt;&gt; 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Val other = (Val) obj; if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) return false; if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) return false; return true; } } public static void main(String... args) throws Exception { ArrayList&lt;Double&gt; list; String line; BufferedReader brMyHashval = new BufferedReader(new InputStreamReader(new FileInputStream("HashProblem.txt"))); Hashtable&lt;Val, ArrayList&lt;Double&gt;&gt; numbers = new Hashtable&lt;Val, ArrayList&lt;Double&gt;&gt;(); while ((line = brMyHashval.readLine()) != null) { if (!(line.isEmpty())) { String[] temp; temp = line.split(" "); Double eDouble = Double.parseDouble(temp[2].toString()); Val key = new Val(Double.parseDouble(temp[0].toString()), Double.parseDouble(temp[1].toString())); if (!(numbers.containsKey(key))) { list = new ArrayList&lt;Double&gt;(); numbers.put(key, list); System.err.println("Created " + key.x + " " + key.y); } else { list = numbers.get(key); } list.add(eDouble); System.err.println("Inserted into " + key.x + " " + key.y + " value " + eDouble + " size " + list.size() + " " + list); } } } </code></pre> <p>The output I get from the logging is</p> <pre><code>Created 1.0 2.0 Inserted into 1.0 2.0 value 9.0 size 1 [9.0] Created 3.0 4.0 Inserted into 3.0 4.0 value 9.0 size 1 [9.0] Created 5.0 6.0 Inserted into 5.0 6.0 value 9.0 size 1 [9.0] Inserted into 1.0 2.0 value 8.0 size 2 [9.0, 8.0] Inserted into 5.0 6.0 value 8.0 size 2 [9.0, 8.0] Inserted into 1.0 2.0 value 7.0 size 3 [9.0, 8.0, 7.0] Created 7.0 8.0 Inserted into 7.0 8.0 value 7.0 size 1 [7.0] Inserted into 3.0 4.0 value 7.0 size 2 [9.0, 7.0] Inserted into 5.0 6.0 value 10.0 size 3 [9.0, 8.0, 10.0] Inserted into 1.0 2.0 value 10.0 size 4 [9.0, 8.0, 7.0, 10.0] Created 1.0 3.0 Inserted into 1.0 3.0 value 10.0 size 1 [10.0] Created 1.0 4.0 Inserted into 1.0 4.0 value 10.0 size 1 [10.0] </code></pre> <p>Isn't that what you'd expect?</p> <p>The other answers has good points about simplifying your hashCode and equals. Also, you do not need to do toString() on object that are already strings.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload