Results 1 to 6 of 6

Thread: Creating a Hash Table in java

  1. #1
    Join Date
    Nov 2009
    Posts
    877

    Creating a Hash Table in java

    Hello, I am learning java programming language and while learning it, I want to create a Hash Table in java. I have tried it, but I am not having any knowledge about it, So, if anyone is having knowledge about it, then please provide me solution for it. If you are having program for getting solution on this, then please reply me with that program.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Creating a Hash Table in java

    Hello, if you want to create a hash table in java then you must need to make use of the different method below:
    • clear()
    • clone()
    • contains(Object value)
    • containsKey(Object key)
    • containsValue(Object value)
    • elements()
    • entrySet()
    • equals(Object o)
    • get(Object key)
    • hashCode()
    • isEmpty()
    • keys()
    • keySet()
    • put(Object key, Object value)
    • putAll(Map t)
    • rehash()
    • remove(Object key)
    • size()
    • toString()
    • values()

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Creating a Hash Table in java

    Hello, for creating a hash table in java you must need to make use of the code below. Just create a class and add all of the above code in that class.
    Code:
    Map M = new HashMap();    
        M = new TreeMap();            
        M.put("x", new Integer(100));
        M.put("y", new Integer(200));
        M.put("z", new Integer(300));    
        int S = M.S();          
        Object obj = M.put("x", new Integer(9));      
        obj = M.remove("c");      
        Iterator iterator = M.keySet().iteratorerator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
        }    
        iterator = M.values().iteratorerator();
        while (iterator.hasNext()) {
            Object value = iterator.next();
        }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Creating a Hash Table in java

    If you want to create a structure in java which contains the key value pair then you must need to make use of the Hashashtableable in java. For creating a hash table in java you must need to make use of the constructor as below:
    Code:
    HashTable hashtable = new HashTable();
    After creating hash table you need to add the data in the hash table. So, for adding the data in the hash table you must need to make use of the code below:
    Code:
    hashtable.put("Number", new Integer(1000)); 
    Integer num = (Integer)numbers.get("Number one");
    if (num != null) 
    {
    System.out.println("Number one = " + num);
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Creating a Hash Table in java

    Hello, I have knowledge of creating a custom hash table. If you want to create a custom hash table then it is necessary to make use of the code below. So, just make use of it and get your problem solved:
    Code:
    import java.util.Hashtable;
    public class CustomHashtable<H, T> extends Hashtable
     {
    @Override  public synchronized T get(Object key) {
    if(key == null) return new Object();
    Object obj = super.get(key);
    if(obj == null)
    {
    return new Object();
    }
    }
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Creating a Hash Table in java

    If many entries are to be made into a Hashtable, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table. This example creates a hashtable of Htable. It uses the names of the Htable as keys:
    Code:
    Hashtable Htable = new Hashtable();
             Htable.put("Eleven", new Integer(11));
             Htable.put("Tweleve", new Integer(12));
             Htable.put("Thirteen", new Integer(13));
    Now if you want to retrieve the number then it is necessary to make use of the code below:
    Code:
    Integer num = (Integer)Htable.get("twelve");
    if (num != null)
    {
    System.out.println("twelve = " + num);
    }

Similar Threads

  1. From Hash Table Remove an Unreferenced Element
    By Level8 in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 05:39 PM
  2. Creating new table from existing table
    By KALANI84 in forum Software Development
    Replies: 3
    Last Post: 29-10-2009, 09:35 PM
  3. Powershell: declare hash table
    By Halina in forum Software Development
    Replies: 3
    Last Post: 02-06-2009, 12:15 AM
  4. Calculating a hash table automatically in SQL
    By Elijah in forum Software Development
    Replies: 4
    Last Post: 02-04-2009, 11:37 PM
  5. Creating xml File from database table in VB.Net
    By Jateen in forum Software Development
    Replies: 2
    Last Post: 29-12-2008, 06:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,572,306.21724 seconds with 16 queries