posted 20 years ago hi friends,
thanx for the tremendous response for clearing my earlier doubt in string-pool.expecting similar responses from u all,i m posting yet another question and its regarding hashtable working.
we know that hashtable stores values as key/value pairs,where both key and value should b an object.
considering this code,
class car
{
int vehnum;
int yearofmake;
public static void main(String args[])
{
car ob1=new car();
car ob2=new car();
Hashtable hs=new Hashtable();
hs.put(ob1,"Raja");
hs.put(ob2,"Alps");
hs.put(ob1,"Rahi");
String s=(String)hs.get(ob1);
System.out.println(s);
}//end of main
}// end of class car
now the o/p obtained is Rahi.i understand why is it so.as i have reffered the key ob1 for Rahi at last.
i want to know how the hashtable retreives the data,and how can i override equals() method,so that key/value pair is unique.
please give thw way as how i should override the equals() method to make my code more efficient.