Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hash Table

 
Balaji Ambresh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a hashtable which contains keys of Strings.
Now i want to check whether a string which will be a substring of any
of the keys of the hashtable is present in the hashtable or not.
For example suppose i am having a key like
"firstpart-secondpart-thirdpart".
Now i want to retrieve a table based on whether "firstpart-secondpart" is present as a
substring of any of the keys or not(in this case it is).
one way to do it is calling keys() method of the hashtable and then
looping through all elements of the enumeration and invoking indexOf()
method of String class.
But i do not want a while or for loop.

Is there any other class in Java API which can help me through this ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Balaji Ambresh:
...But i do not want a while or for loop...

Why not? It sounds like you will need to iterate through an Enumeration (or Set) in some way. What kind of alternative are you looking for?
 
Eric Daly
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does java support the "goto" statement? Haha, just kidding. Or what about the do while loop?
[ April 03, 2007: Message edited by: Eric Daly ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic