Performance and Memory allocation comparison between List and Set

后端 未结 6 1259
执笔经年
执笔经年 2020-12-02 14:00

I want to know the comparison between List and Set in terms of performance,memory allocation and usability.

If i don\'t have any requirement of keeping the uniquenes

6条回答
  •  天命终不由人
    2020-12-02 14:46

    HashSet consumes about 5.5 times more memory than ArrayList for the same number of elements (although they're both still linear), and has significantly slower iteration (albeit with the same asymptotics); a quick Google search suggests a 2-3x slowdown for HashSet iteration versus ArrayList.

    If you don't care about uniqueness or the performance of contains, then use ArrayList.

提交回复
热议问题