日期:2014-05-20  浏览次数:20610 次

问个Map接口的问题
import java.util.*;
public class TestMap {
  public static void main(String args[]) {
    Map m1 = new HashMap(); 
    Map m2 = new TreeMap();
    //m1.put("one",new Integer(1));
    m1.put("one", 1);
    //m1.put("two",new Integer(2));
    m1.put("two", 2);
    //m1.put("three",new Integer(3));
    m1.put("three", 3);
    //m2.put("A",new Integer(1));
    m2.put("A", 1);
    //m2.put("B",new Integer(2));
    m2.put("B", 2);
    System.out.println(m1.size());
    System.out.println(m1.containsKey("one"));
    System.out.println
        //(m2.containsValue(new Integer(1)));
        (m2.containsValue(1));
    if(m1.containsKey("two")) {
      //int i = ((Integer)m1.get("two")).intValue();
      int i = (Integer)m1.get("two");
      System.out.println(i);
    }
    Map m3 = new HashMap(m1);
    m3.putAll(m2);
    System.out.println(m3);
  }
}


我在自学马士兵老师的视频教程,这段代码是他给的例子中的,我先自己写,编译的时候出现28个错误,然后我找到了他的源代码,编译还是28个错误,这28个错误基本都是can not find symbol 这种错误,求解到底是怎么回事,看视频老师在自己的机器上明明编译成功了
------解决方案--------------------
看你贴的代码,没什么问题,就是用了jdk1.5及以上的自动拆装箱,如 m1.put("one", 1);
所以只要你的jdk是1.5及以上版本应该不会有问题。
------解决方案--------------------
楼上说的对,可能是你的eclipse的配置问题,也就是说你的eclipse用的JDK版本不同,1.5之前的版本不支持自动装箱。
可能你用editplus,环境变量中的JDK版本太低。