HashSet vs. List performance

前端 未结 12 2398
小鲜肉
小鲜肉 2020-11-22 09:19

It\'s clear that a search performance of the generic HashSet class is higher than of the generic List class. Just compare the has

12条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 09:31

    Depends on a lot of factors... List implementation, CPU architecture, JVM, loop semantics, complexity of equals method, etc... By the time the list gets big enough to effectively benchmark (1000+ elements), Hash-based binary lookups beat linear searches hands-down, and the difference only scales up from there.

    Hope this helps!

提交回复
热议问题