Hash Map奇闻怪事

为什么用containsValue();判断HashMap是否包含字符串“憨憨”,返回值却是true???

    public static void main(String[] args) {
        HashMap hm =new HashMap();
//        hm.put(1000,"张飞");
         hm.put(1001,"刘备");
//        hm.put(1002,"关羽");
        boolean res2 = hm.containsValue("憨憨"); // true
        System.out.println(res2);
    }

为了缩小范围,判断条件不变:“憨憨”,
一次只放入一条key-value键值对,结果如下:
张飞:憨憨 // false
刘备:憨憨 // true
关羽:憨憨 // true

posted @ 2022-03-23 10:47  TabKey9  阅读(26)  评论(1编辑  收藏  举报