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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -