I try to do it in the following way:
public String getValue(String service, String parameter) {
String inputKey = service + ":" + parameter;
Set keys = name2value.keySet();
Iterator itr = keys.iterator();
while (itr.hasNext()) {
if (inputKey.equal(itr.next())) {
return name2value.get(inputKey);
}
return "";
}
}
And I get an error message: cannot find symbol method.equal(java.lang.Object).
I think it is because itr.next() is not considered as a string. How can I solve this problem? I tried to replace Set keys by Set<String> keys. It did not help.
The method you want is called
equalsnotequal.However there are a few other flaws in your code.
Firstly you should not be looping through all keys in a
Mapto find a specific key, just usegetand/orcontainsKey.The second
returnis also wrong. It will return""if the first key does not match. If you want to return""when none of the keys match, thereturnshould go at the end of the method e.g.: