Type mismatch: cannot convert from element type Object to Map.Entry<String,String> 怎么解决

public class TNull
{
public static void main(String[] args)
{

    Map writers = new HashMap<String,String>();

    writers.put("01", "01");
    writers.put("02", "02");
    writers.put("03", "03");
    writers.put("04", "04");
    writers.put("05", "05");


    System.out.println("通过Map.entrySet遍历key和value");    
    for (Map.Entry<String, String> entry : writers.entrySet()) 
    {    
      System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());    
    }   

}
}

2个回答

代码在 writers.entrySet()这里提示错误

 Map writers = new HashMap<String,String>();

改成:

 Map<String, String> writers = new HashMap<String,String>();
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!