• java IdentityHashMap 与HashMap


    这两个map的主要区别在于,比较key值什么时候:
    IdentityHashMap我觉得当k1 == k2 时刻key值一样的
    HaspMap觉得k1 == null ? k2 == null:k1.equals(k2)时key值是一样的

    举个样例:
    Integer a = new Integer(123456);
               Integer b = new Integer(123456);
               HashMap hashMap = new HashMap();
               IdentityHashMap identityHashMap = new IdentityHashMap();
               hashMap.put(a,1);
               hashMap.put(b, 2);
               identityHashMap.put(a,1);
               identityHashMap.put(b,2);
               System.out.println(hashMap);
               System.out.println(identityHashMap);

    执行结果:
    P_LOG: {123456=2}
    P_LOG: {123456=1, 123456=2}

    总结:
              HashMap:会使用equals比較key对象
              IdentityHashMap:使用 == 比較key对象
          



    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    高斯消元
    UVa12103
    UVa10294
    UVa11762
    牛客网算法工程师能力评估
    华为研发工程师编程题
    网易2017春招笔试真题编程题集合
    2017网易有道内推编程题
    2017网易雷火实习生招聘编程题
    数组---面试知识点整理
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4845657.html
Copyright © 2020-2023  润新知