class Student2{
int age;
String name;
Student2(int age,String name)
{
this.age=age;
this.name=name;
}
/*
public int hashCode(){
return age;
}
*/
public boolean equals(Object o){
Student2 s2=(Student2)o;
return (this.age==s2.age && this.name==s2.name);
}
}
public class HashMapDemo{
public static void main(String a[])
{ Map m=new HashMap();
m.put(new Student2(10,"sameer"), 1);
m.put(new Student2(11,"pagal"), 2);
m.put(new Student2(12,"ullu"), 3);
m.put(new Student2(13,"lullu"), 5);
System.out.println(m.get(new Student2(11,"pagal")));
}
}
HashMap... here getting null, i've to overload hashcode() inorder to my respective object. what i've to add in hashCode. my doubt is in hashCode method is it mandatory to override hashCode method.