guyeuro
V2EX  ›  问与答

Java HashMap, ConcurrentHashMap 等的 key 的类型对性能的影响?

  •  
  •   guyeuro · Aug 21, 2017 · 1858 views
    This topic created in 3368 days ago, the information mentioned may be changed or developed.

    比如 key 用 String 类型或者 Class 类型,哪个性能更好?

    字符串长度多长冲突概率小而且性能又适中?

    2 replies  •  2017-08-21 16:22:11 +08:00
    SoloCompany
    SoloCompany
    Aug 21, 2017
    1
    [@]See java.langObject#hashCode
    geelaw
    geelaw
    Aug 21, 2017
    2
    没有影响,毕竟类型擦除。

    当然用自己的 class 的时候要实现一个好的 hashCode。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2988 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:45 · PVG 08:45 · LAX 16:45 · JFK 19:45
    ♥ Do have faith in what you're doing.