0

I have a HashMap with country names as keys. I also have a JSON file for alternate names that can be used for these countries.

Now, I need to ask the user for a country name and proceed accordingly. If they give a valid country name, my code will match the input with the keys present in the HashMap. If no match is found here, it will try to match the input in the JSON file containing the alternate names.

The problem is that the input will match only if the user gives the exact country name. In case they make even a tiny spelling mistake, match won't be found.

To overcome this, I'm thinking of using Soundex so that if someone makes a spelling mistake in the country name, my code will ask them if they meant so and so country.

e.g.

(Code) Enter country name here:

(User) Unted Stats of America (spelling mistakes here)

(Code) Did you mean United States of America?

I would really appreciate it if someone could give some useful tips on matching the country name efficiently as I don't want my code to match the input with all values present in the HashMap or the JSON file.

Thanks.

KKG
  • 11
  • 3

0 Answers0