| Author |
hashtable working & overriding equals()
|
rajaraman navaneethan
Ranch Hand
Joined: Feb 26, 2005
Posts: 86
|
|
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.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Please don't post duplicate threads. It just wastes people's time if they answer a question that's already been answered elsewhere. I'm closing this one.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: hashtable working & overriding equals()
|
|
|