I would like to have a HashMap with only one key.
I created the following HashMap :
HashMap <Integer,String>DocsCollection = new HashMap <Integer,String>();
In HashMap, I would like to have only one record / object. The key type is an integer. The value type is a string.
eg. = <1, "foo.txt">
Every time I find a specific word in a file, I would like
eg. Say I'm looking for the word “Hello” in a DocsCollection , I have to store the term “frequency” for each occurrence of the word “Hello” and merge the new file with the previous value.
<3, "foo.txt, hello.txt, test.txt">
3 means that I found the word "Hello" in three files.
and the value consists of files in which the word was found
If I use the put method, a new entry is created in the HashMap because the key is changing. It is not stable. It starts with "1", but when I find the word a second time, the key is incremented, and then the put method inserts a new record with a new key. But I would like to have only one record and change the key. It can be done? How can I have only one object in the HashMap and change the key every time?
DocsCollection.put(2,"foo.txt,hello.txt");
Thanks in advance
java hashmap
programmer
source share