hash map

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: hash map

  1. #1
    Join Date
    Sep 2005

    hash map

    working of hash map with an example

  2. #2
    Join Date
    Aug 2005
    Suppose you want to maintain a simple address book. Here is an example:

    //create the hashmap
    HashMap map = new HashMap();
    //add 3 address book items
    map.put("Steve", "1501 Busy Ave.");
    map.put("Mary", "888 Somewhere CT.");
    map.put("Brenda", "111 Java Ave.");
    //get the address of steve from the map (must cast)
    String stevesAddress = (String)( map.get("Steve") );
    //get the address of bob from the map (must cast)
    //this line returns NULL b/c Bob isn't in the address book
    String bobAddress = (String)( map.get("Bob") );
    In hashmap terminology, the names of the people are called keys and the addresses are called the values of the hashmap.

    When you have a key (a name) , you can use the get() method to get the correspoding value (an address).

    It is best to use a hashmap when you don't need the keys to be sorted. Hashmaps are very "fast". If you need this functionality, use a TreeMap instead. Treemaps are "slower" than HashMaps.

    For more help, www.NeedProgrammingHelp.com

  3. #3
    Join Date
    Sep 2005
    17 examples for hash map and hash table

Similar Threads

  1. need help for Hash Function in Java
    By alirazvi in forum Java
    Replies: 0
    Last Post: 08-18-2005, 11:43 AM
  2. Replies: 10
    Last Post: 04-06-2005, 05:30 PM
  3. Re: Looking for some magic . . . With Hashing
    By Patrick Ireland in forum .NET
    Replies: 0
    Last Post: 08-02-2001, 05:22 PM
  4. Looking for a good site map tool
    By Woody Medina in forum Architecture and Design
    Replies: 4
    Last Post: 08-01-2001, 07:40 AM
  5. map areas not passing Form object to java script
    By mark hembree in forum ASP.NET
    Replies: 1
    Last Post: 01-11-2001, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center