I have a map that contains a user entered remote machine name, and a user entered name on the host for a program running there. Don't want duplicate entries because the user typed upper case once then entered the same name in lowercase later.
Proto:
map<string, string> host_and_name = 1;
When storing, ideally I'd be able to use this method, because the map is marked case sensitive. Not the default behavior though, and don't see a way to decorate otherwise. Hoping I'm missing something.
cache.putHostAndHame( hostName, strategyName );
Aware I could iterate all map values and only put if I don't find an equalsCaseInsenstive match. I'll end up doing that if I have to, seems a bit brute force though.
if you need to validate and put in your host_and_name map you can convert the all characters to lowercase and whenever you put every host or name it will get all the characters to lower case.
like below
import java.io.*;
public class Test {
public static void main(String args[]) {
String str = "My Sample Text";
System.out.print("Return Value :");
System.out.println(str.toLowerCase());
}
}
Return Value :my sample text
and also you can put it on your map and make a foreach loop to check host or name is already in the map. check this
I hope you get the idea. if there any question comment below. thanks.
Also this question have a good answers what you need to implement.