aspose file tools*
The moose likes Beginning Java and the fly likes Strings and Hashtables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strings and Hashtables" Watch "Strings and Hashtables" New topic
Author

Strings and Hashtables

Charmaine Gatling
Greenhorn

Joined: Jan 10, 2002
Posts: 11
Is there a way to compare the keys in a hashtable to a string? I need to find out if any key is found anywhere in a string. I know with a string you can use indexOf() to see if one string is a substring of another but how do you traverse a hashtable in order to do the same thing?
I how this is clear...it's the only way I know how to explain it.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Map.keySet() will give you all the keys in the Map. The remaining work is up to you...
[ August 23, 2002: Message edited by: Ilja Preuss ]

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dermot Curley
Ranch Hand

Joined: Jul 03, 2002
Posts: 43
you could do it as follows:
Charmaine Gatling
Greenhorn

Joined: Jan 10, 2002
Posts: 11
So, I'd basically have to store the key into a list (array) in order to compare each one to the string? Then what does the containsValue() method do?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Charmaine Gatling:
So, I'd basically have to store the key into a list (array) in order to compare each one to the string? Then what does the containsValue() method do?

Contains value tells you if the object is found in the value part of the hashtables key-value pair. It does not check if the value contains something. It checks to see if the hashtable contains some value.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Sun recommends using HashMap and Iterator instead of Hashtable and Enumeration, unless you're stuck with a pre-1.2 Java.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strings and Hashtables