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

原文地址:https://www.cnblogs.com/maydow/p/4525682.html