• 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

about enumeration of hashtable

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic