• Post Reply Bookmark Topic Watch Topic
  • New Topic

about enumeration of hashtable  RSS feed

 
david hu
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());
}
 
Valentin Crettaz
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
 
Ruchi Kolla
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!