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 in map, 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

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -