Results 1 to 2 of 2

Thread: Hashing

  1. #1
    sravan_51 is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default Hashing

    Hello please help me with this code

    here wordcnt is a hashtable

    }//for words that are repeated more than once

    }//word that is first appeared

    The problem here is that if the word appeared for more than once its got replaced by 2nd one ...
    If I want to have both the first and next appeared words what I can do?

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Stockholm, Sweden
    Blog Entries
    Rep Power


    If you want to store Object instances with String keys and
    want to save all appearances of the key chronologically you can use
    HashMap<String, ArrayList<Object>>:

    Java Code:
    HashMap<String, ArrayList<Object>> map = new HashMap<String, ArrayList<Object>>();
    //A word is found and assigned to the variable 'key',
    //the value to store is assigned to 'value'.
    ArrayList<Object> list = map.get(key); //null if it does not exist yes
    if (list == null)
        list = new ArrayList<Object>();
        map.put(key, list);

Similar Threads

  1. My Simple Hashing Program
    By Simplev_v in forum New To Java
    Replies: 4
    Last Post: 09-07-2009, 06:10 PM
  2. Hashing problem
    By etherkye in forum Java Applets
    Replies: 0
    Last Post: 07-23-2009, 12:56 PM
  3. Hashing and Searching Benchmarking
    By peterdfl in forum New To Java
    Replies: 0
    Last Post: 12-07-2008, 11:28 PM
  4. Hashing in Java
    By ajaykushwaha in forum New To Java
    Replies: 1
    Last Post: 11-17-2008, 01:51 PM
  5. Hash table with double hashing
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts