java - ArrayList custom class as HashMap key -
i want store data in hashmap<point[], double>
. used iteration assign data, when checked @ end, number of elements 1. have implemented hashcode()
, equals()
in custom class point.
hashmap<point[], double> hmdistord = new hashmap<point[], double>(); point[] keypts = new point[2]; (int i=0; i<intersectionpts.size(); i++) { p1 = intersectionpts.get(i); (int j=0; j<intersectionpts.size(); j++) { p2 = intersectionpts.get(j); if (!p1.equals(p2)) { keypts[0] = p1; keypts[1] = p2; d = p1.distance(p2); hmdistord.put(keypts, d); } } }
any hints? in advance!
you can't use array key, array has default implementation of hashcode
, equals
objects
, doesn't consider it's elements.
to make work had override hashcode
, equals
of array, can't it.
you can use arraylist
instead, implements hashcode
end equals
comparing elements.
Comments
Post a Comment