File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes hashtable working & overriding equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "hashtable working & overriding equals()" Watch "hashtable working & overriding equals()" New topic

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();


String s=(String)hs.get(ob1);
}//end of main

}// end of class car

now the o/p obtained is Rahi.i understand why is it 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

Joined: Jul 08, 2003
Posts: 24199

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]
I agree. Here's the link:
subject: hashtable working & overriding equals()
It's not a secret anymore!