作者:mobiledu2402852413 | 来源:互联网 | 2023-05-24 16:14
我有编译错误:
Error: incompatible types: Object cannot be converted to String.
在线 String buf = it.next();
public String getMostFrequentColor() {
HashMap colors = countColors();
int count = 0;
String mfcolour;
Iterator it = colors.keySet().iterator();
while (it.hasNext()) {
String buf = it.next();
if (colors.get(buf) > count) {
count = colors.get(buf);
mfcolour = buf;
}
}
return mfcolour;
}
我不知道为什么会发生这种情况.it.next()
在我看来应该返回一个字符串.
1> Bubletan..:
用Iterator
而不是Iterator
.
Iterator it = colors.keySet().iterator();