[英]java.util.Map.Entry cannot be resolved error
I tried the following code as 我尝试了以下代码
package collectconstructor;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class QuestionMap {
private int id;
private String name;
private Map<String,String> answers;
public QuestionMap(int id, String name, Map<String, String> answers) {
super();
this.id = id;
this.name = name;
this.answers = answers;
}
public void displayInfo(){
System.out.println("question id:"+id);
System.out.println("question name:"+name);
System.out.println("Answers....");
Set<Entry<String, String>> set=answers.entrySet();
Iterator<Entry<String, String>> itr=set.iterator();
while(itr.hasNext()){
Entry entry= itr.next();
System.out.println("Answer:"+entry.getKey()+" Posted By:"+entry.getValue());
}
}
}
Here in the following code snippet 在下面的代码片段中
Set<Entry<String, String>> set=answers.entrySet();
Iterator<Entry<String, String>> itr=set.iterator();
I got the error as the 我得到了错误
Multiple markers at this line 这行有多个标记
The method entrySet() from the type Map refers to the missing type Map$Entry Map类型的方法entrySet()引用缺少的Map $ Entry类型
Entry cannot be resolved to a type 条目无法解析为类型
Can anybody explain as Why I am getting this error? 有人可以解释为为什么我会收到此错误吗?
Also I tried importing 我也尝试导入
import java.util.Map.Entry;
but got same error.. please help!! 但是有同样的错误..请帮助!!
Try this: 尝试这个:
Set<Map.Entry<String, String>> set = answers.entrySet();
Iterator<Map.Entry<String, String>> itr = set.iterator();
Here Map.Entry
is the sub interface of Map. 这里的Map.Entry
是Map的子接口。 So we will be accessed it by Map.Entry
name. 因此,将通过Map.Entry
名称对其进行访问。 It provides methods to get key and value. 它提供了获取关键和价值的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.