A basic chat program I wrote has several key words that generate special actions, images, messages, etc. I store all of the key words and special functions in a HashMap. Key words are the keys and functions are the values. I want to compare user input to the keys with some type of loop. I have tried everything I can think of and nothing works. This is what I can figure out:
myHashMap = <File Input>
for(String currentKey : <List of HashMap Keys>){
if(user.getInput().equalsIgnoreCase(currentKey)){
//Do related Value action
}
}
...
I would appreciate any help. Forgive me if I overlooked a similar question or if the answer is obvious.
Well, you can write:
but this isn’t really the best way to use a hash-map.
A better approach is to populate
myHashMapwith all-lowercase keys, and then write:to retrieve the function (or
nullif the user-input does not appear in the map).