Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2008, 09:44 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Demonstration of the Hashtable class, and an Enumeration
Code:
import java.util.Enumeration; import java.util.Hashtable; /** * Demonstrate the Hashtable class, and an Enumeration. * * @see HashMapDemo, for the newer HashMap class. */ public class HashtableDemo { public static void main(String[] argv) { // Construct and load the hash. This simulates loading a // database or reading from a file, or wherever the data is. Hashtable h = new Hashtable(); // The hash maps from company name to address. // In real life this might map to an Address object... h.put("Adobe", "Mountain View, CA"); h.put("IBM", "White Plains, NY"); h.put("Learning Tree", "Los Angeles, CA"); h.put("Microsoft", "Redmond, WA"); h.put("Netscape", "Mountain View, CA"); h.put("O'Reilly", "Sebastopol, CA"); h.put("Sun", "Mountain View, CA"); // Two versions of the "retrieval" phase. // Version 1: get one pair's value given its key // (presumably the key would really come from user input): String queryString = "O'Reilly"; System.out.println("You asked about " + queryString + "."); String resultString = (String) h.get(queryString); System.out.println("They are located in: " + resultString); System.out.println(); // Version 2: get ALL the keys and pairs // (maybe to print a report, or to save to disk) Enumeration k = h.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); System.out.println("Key " + key + "; Value " + (String) h.get(key)); } } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Demonstration of Stack class in java.util package Java Tip java.lang 0 04-16-2008 11:33 PM
TreeSet Demonstration Java Tip java.lang 0 04-15-2008 08:34 PM
Using Enumeration to iterate through Hashtable Java Tip Java Tips 0 02-15-2008 09:44 AM
Using Enumeration to get items out of the session Java Tip Java Tips 0 01-04-2008 10:34 AM
Declaring Enumeration Java Tip Java Tips 0 11-04-2007 06:59 PM


All times are GMT +3. The time now is 11:30 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org