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!!
但得到同样的错误..请帮助!!
1 个解决方案
#1
0
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. So we will be accessed it by Map.Entry
name. It provides methods to get key and value.
这里Map.Entry是Map的子接口。因此我们将通过Map.Entry名称访问它。它提供了获取密钥和值的方法。
#1
0
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. So we will be accessed it by Map.Entry
name. It provides methods to get key and value.
这里Map.Entry是Map的子接口。因此我们将通过Map.Entry名称访问它。它提供了获取密钥和值的方法。