本帖最后由 马晓平 于 2013-11-1 23:21 编辑
是什么原因会报错呢?请大家帮忙找一下吧,代码如下:
import java.util.*;
class ForEachDemo
{
public static void main(String[] args)
{
ArrayList<String>al=new ArrayList<String>();
al.add("abs01");
al.add("abs02");
al.add("abs03");
al.add("abs04");
for(String s:al)
{
s="kk";
System.out.println(s);
}
System.out.println(al);
/*
Iterator<String>it=al.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
*/
int[] arr={9,3,5};
for(int i:arr)
{
System.out.println("i:"+i);
}
HashMap<Integer,String>hm=new HashMap<Integer,String>();
hm.put(1,"a");
hm.put(2,"b");
hm.put(3,"c");
hm.put(4,"d");
Set<Integer> KeySet=hm.keySet();
for(Integer i : keySet)
{
System.out.println(i+"::"+hm.get(i));
}
}
}
就是最后的for循环中的keySet显示的错误
异常如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
keySet cannot be resolved to a variable
请大家帮忙找一下吧谢了
|