Should I use a `HashSet` or a `TreeSet` for a very large dataset?

后端 未结 2 1453
一个人的身影
一个人的身影 2021-02-09 00:44

I have a requirement to store 2 to 15 million Accounts (which are a String of length 15) in a data structure for lookup purpose and checking uniqueness. Initially I

2条回答
  •  不要未来只要你来
    2021-02-09 01:32

    When we tried to store 50 million records in HashMap with proper initialization parameters, insertion started to slowdown, especially after 35 million records. Changing to TreeMap gave a constant insertion and retrieval performance.

    Observation : TreeMap will give better performance than a HashMap for large input set. For a smaller set, of course HashMap will give better performance.

提交回复
热议问题