java - returning specific values from a hashmap -
java - returning specific values from a hashmap -
i have dictionary of terms dictonery/ab.txt
, big text file dictonery/annotate.txt
.
i want know dictionary terms in ab.txt
in annotate.txt
file.
here code far:
string filestring = new string(files.readallbytes(paths.get("dictonery/ab.txt")), standardcharsets.utf_8); map<string, string> map = new hashmap<string, string>(); string entirefiletext = new scanner(new file("dictonery/annotate.txt")).usedelimiter("\\a").next(); map.put(filestring, "m"); (string key : map.keyset()) { if(filestring.contains(key)) { system.out.print(key); } }
at moment whole dictionery returned. how can specific terms in annotator.txt
file?
there's few things might help:
since don't need values inmap
, utilize set
(specifically hashset
). use scanner.next()
read individual words instead of entire file @ once your check filestring.contains(key)
pretty inefficient, , homecoming true
partial matches (if dictionary has word "do", match "dog"). print matching words multiple times. personally, create 2 sets, read both files same way, , calculate intersection. if want sorted output (probably not requirement, nice), create set
iterate on treeset
.
java hashmap
Comments
Post a Comment