Results 1 to 2 of 2
Thread: Hashing
- 12-28-2010, 04:26 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Hashing
Hello please help me with this code
here wordcnt is a hashtable
if(wordcnt.containsKey(key_value))
{
wordcnt.put(key_value,sen_cnt);
}//for words that are repeated more than once
else
{
wordcnt.put(key_value,sen_cnt);
}//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?
- 12-28-2010, 04:47 AM #2
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
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); } list.add(value);
Similar Threads
-
My Simple Hashing Program
By Simplev_v in forum New To JavaReplies: 4Last Post: 09-07-2009, 06:10 PM -
Hashing problem
By etherkye in forum Java AppletsReplies: 0Last Post: 07-23-2009, 12:56 PM -
Hashing and Searching Benchmarking
By peterdfl in forum New To JavaReplies: 0Last Post: 12-07-2008, 10:28 PM -
Hashing in Java
By ajaykushwaha in forum New To JavaReplies: 1Last Post: 11-17-2008, 12:51 PM -
Hash table with double hashing
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks