I have map table
public static final String key1 = "newKey";
public static final String key2 = "key2";
public static final String key3 = "key3";
public static final String key4 = "key4";
public static Map<String, String> objects = new TreeMap<String, String>();
TreeMap.put(key1,"Bob1")
TreeMap.put(key2,"Bob2")
TreeMap.put(key3,"Bob3")
TreeMap.put(key4,"Bob4")
The first parameter is the key. I want to check if the key exists. So I wrote this code
public String checkKey(String keyToCheck) {
if (objects.containsKey(keyToCheck)) {
.......
}
}
The problem is that the user could call checkKey
in these two ways:
checkKey("newkey")
checkKey("className.key1")
Either of these strings come from user input. In the first case, I don't have any problems because it's in the map. But in the second case, I need to convert it so that I can get the corresponding newkey
value.