Map里面存放的是对象的引用

public class Main {
    public static void main(String[] args) {
        Map< Integer, Stu> mapA=new HashMap<Integer, Stu>();
        Map<String, Stu> mapB=new HashMap<String, Stu>();
        Stu stu=new Stu();
        stu.x=10;
        stu.y=10;
        mapA.put(1, stu);
        mapB.put("1", stu);
        System.out.println(mapA.get(1).x);
        stu.x=5;
        System.out.println(mapB.get("1").x);
        System.out.println(mapA.get(1).equals(mapB.get("1")));
    }

输出
10
5
true

 

posted @ 2015-05-24 12:56  Maydow  阅读(2009)  评论(0编辑  收藏  举报