java - How can a HashMap consist only of one entry/object? -
java - How can a HashMap consist only of one entry/object? -
i have hashmap 1 key-value object.
i have created next hashmap:
hashmap <integer,string>docscollection = new hashmap <integer,string>(); in hashmap have 1 entry/object. key type integer. value type string.
e.g. = <1,"foo.txt">
every time find specific word in file to
increment counter in key
add new file in value
e.g. let's i'm searching word "hello" in docscollection, have store every appearance of word "hello" term frequency , concatenate new file previous value.
<3,"foo.txt,hello.txt,test.txt">
3 means i've found word "hello" in 3 files.
and value consists of files word found
if utilize method put, new entry created in hashmap cause key changes. it's not stable. begins "1" when find word sec time , key increments , set method inserts new entry new key have 1 entry , modify key. can done? how can have 1 object in hashmap , modify key every time?
docscollection.put(2,"foo.txt,hello.txt"); thanks, in advance
the map approach might not best. issue changing key value.
note might improve have list<string>, , everytime match word, add together file list. can count list.size()
java hashmap
Comments
Post a Comment