public static void main(String[] args) {
HashMap<String,Integer> h1=new HashMap<String,Integer>();
h1.put("A", 1);
h1.put("B", 2);
HashMap<String,Integer> h2=new HashMap<String,Integer>();
h2.put("C",3);
h2.putAll(h1);
for(Map.Entry m: h2.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());}
}
但是这段代码会报错
public static void main(String[] args) {
HashMap<String,Integer> h1=new HashMap<String,Integer>();
h1.put("A", 1);
h1.put("B", 2);
HashMap<String,Integer> h2=new HashMap<String,Integer>();
h2.put("C",3);
for(Map.Entry m: h2.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());}
}
h2.putAll(h1);
区别只是putall代码在Map.Entry代码的前面还是后面
报错内容为:
Multiple markers at this line
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "SimpleName" to complete QualifiedName
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error, insert ")" to complete MethodDeclaration
希望能有人解答,感谢!
你的括号是不是没对好。。放在方法外了吧,怎么循环里面有个花括号的。。