Set is not working with overridden equals
问题 I was trying to use set. so i tried this way HashSet set=new HashSet(); Points p1 = new Points(10, 20); Points p2 = new Points(10, 20); System.out.println(set.add(p1)); // output true System.out.println(set.add(p2)); // output false I know my first output will be true and second will be false as Set will not allow duplicate elements. And, i also know Set achieve this by using equals(Object o) method. Which comes from java Object class with following signature. public boolean equals(Object o)