• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strings and Hashtables

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you could do it as follows:
 
Charmaine Gatling
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun recommends using HashMap and Iterator instead of Hashtable and Enumeration, unless you're stuck with a pre-1.2 Java.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic