Hash Set and Array List performances

后端 未结 4 1327
迷失自我
迷失自我 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 03:00

    They're completely different classes, so the question is: what kind of behaviour do you want?

    HashSet ensures there are no duplicates, gives you an O(1) contains() method but doesn't preserve order.
    ArrayList doesn't ensure there are no duplicates, contains() is O(n) but you can control the order of the entries.

提交回复
热议问题