Hash Set and Array List performances

后端 未结 4 1323
迷失自我
迷失自我 2020-11-30 02:27

I have implemented a method which simply loops around a set of CSV files that contain data on a number of different module. This then adds the \'moduleName\' into a hashSet.

4条回答
  •  时光取名叫无心
    2020-11-30 02:59

    I believe using the hash set has a better performance than an array list. Am I correct in stating that?

    With many (whatever it means) entries, yes. With small data sizes, raw linear search could be faster than hashing, though. Where exactly the break-even is, you have to just measure. My gut feeling is that with fewer than 10 elements, linear look-up is probably faster; with more than 100 elements hashing is probably faster, but that's just my feeling...

    Lookup from a HashSet is constant time, O(1), provided that the hashCode implementation of the elements is sane. Linear look-up from a list is linear time, O(n).

提交回复
热议问题