码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-24 14:11:39      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!