Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with containsKey()

Status
Not open for further replies.

duan

Technical User
May 30, 2001
9
GB
Dear all,

Got problems with HashMap.containsKey()..
Here is the key code:

if ( Word_Def.get("language")!=null )
{System.out.println(Word_Def.get("language"));}

Word_Def is a HashMap stored the word and its definition. Word_Def has been created by reading a chopped file.
I want to look up a word in Word_Def by using containsKey() method, unluckly it doesn't work???!!!

Any body got same experience on it? Tell me why....

Very thanks for your help...!!!

jane
 
are u sure all the values are added to the hashmap correctly? just because null is returned, it does not mean the entry doesn't exist. it is possible the entry for language is pointing to a null object. you should add some diagnostic code that prints to the screen the entire content of the map to varify everything was added correctly.
 
Yes.I'v checked Word_Def. Info. has been added in it properly. it also can be print out on the screen. It's true some stuff in it. I also checked if the words contains white space which can cause the problem.

Any help?

j.
 
Send me your code and I'll check it out. So sounds as if it should all work. We must be missing something basic.

meadandale@yahoo.com

charles
 
Thanks guys!

I found I made a mistake when read in words from file.
one method should be applied for each chopped words.
Word.trim();

it works now!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top