This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

about enumeration of hashtable  RSS feed

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I created a hashtable which contains many key(url) and value(the name of the web pages) pairs. What I want to do is to enumerate the hashtable, printf each key and value pairs. But when I use the following code only value is printed, but I want both key and value printed, how should I do?
for(Enumeration e = hashtable1.elements(); e.hasMoreElements(); ){
System.out.println(e.nextElement());
}
 
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Instead of giving you the solution right away, I'm gonna put you in the right direction...
Remember what you said, you have keys which are mapped to values in a hashtable. Example
http://www.a.com ---> Site A
http://www.b.com ---> Site B
http://www.c.com ---> Site C
http://www.d.com ---> Site D
Now understand that in order to retrieve the name of each web site, that is, all "values" in the hashtable, you first have to get the "keys". Once you have the keys, you can iterate through them and ask the hastable to which value the key is mapped...
Try to give it another shot, and come back if you don't find
HIH
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!