How to make a loop over all keys of a HashMap?
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-03-23T15:47:03Z
Indexed on
2010/03/23
15:53 UTC
Read the original article
Hit count: 360
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.
© Stack Overflow or respective owner