You've entirely missed the point of a HashMap
if you're attempting to search through it. A HashMap
is designed to subvert the need to search, by using the value as the key
.
if(map.containsKey(userInput))
{
return map.get(userInput);
}
This is what is meant by HashMap
having an O(1)
complexity when searching. You only ever need to iterate or recurse once.
Additionally (sorry), it has to be bilingual, could I simply have all the words in both languages in one HashMap and have a way to search through both?
Yes. Just add new entries to the HashMap
.
map.put("Hello", "A greeting");
map.put("Hola", "Una greetingo"); // Forgive my slightly racist Spanish.
Extra (In your case Necessary) Reading
- Read up on the HashMap. You need to learn some basic stuff about the object. You're out of your depth because you haven't spent the appropriate time learning about the problem.