I would like to have a HashMap
with only one key-value object.
I have created the following HashMap
:
HashMap <Integer,String>DocsCollection = new HashMap <Integer,String>();
In the HashMap I would like to have only one entry/object. The key type is an Integer. The value type is a String.
e.g. = <1,"foo.txt">
Every time I find a specific word in a file I would like to
Increment the counter in key
Add the new file in the value
e.g. Let's say that I'm searching for the word "Hello" in a DocsCollection
,
I have to store for every appearance of the word "Hello" the term frequency and concatenate the new file to the previous value.
<3,"foo.txt,hello.txt,test.txt">
3 means that I've found the word "Hello" in three files.
and the Value consists of the files where the word was found
If I use the method put, a new entry is created in the HashMap
cause the key changes.
It's not stable. It begins with "1" but when I find the word second time , the key increments and then the put method inserts a new entry with a new key
But i would like to have only one entry and modify the key.
Can this be done?
How can i have only one object in a HashMap and modify the key every time?
DocsCollection.put(2,"foo.txt,hello.txt");
Thanks, in advance