【发布时间】:2016-04-11 15:05:12
【问题描述】:
我创建了一个哈希表:
Hashtable next_hop = new Hashtable();
我插入诸如 next_hop.put("R1","local") 之类的值...
哈希表如下所示:
{R5=R5, R4=R2, R3=R2, R2=R2, R1=Local}
现在我尝试从键中检索值,如下所示:
String endPoint = "R1";
for (Object o: next_hop.entrySet()) {
Map.Entry entry = (Map.Entry) o;
if(entry.getKey().equals(endPoint)){
String nextHopInt = entry.getValue();
}
}
我收到以下错误:
错误:不兼容的类型
String nextHopInt = entry.getValue();
必需:字符串
找到:对象
【问题讨论】:
-
不要使用原始类型。