##Merge2Lists的功能 将两个list合并为一个集合,并且需要去掉重复元素。
使用不同集合的API来处理效率也差异很大。
##合并的效率?
- List集合API的使用
- 1W条数据,只有一个元素重复,去重合并使用的时间为[987]ms,size数为19999;
- 10W条数据,只有一个元素重复,去重合并使用的时间为[103817]ms,size数为199999;
- Set集合API的使用
- 1W条数据,只有一个元素重复,去重合并使用的时间为[11]ms,size数为19999;
- 10W条数据,只有一个元素重复,去重合并使用的时间为[145]ms,size数为199999;
##得出的结论
- List集合在处理removeAll时需要进行迭代遍历,每一个元素都要调用contains方法来过滤重复元素,addAll方法则是通过拷贝的方式进行处理的;
- Set集合只需要调用addAll方法时,将添加的元素作为HashMap中的key来判读是否已经存在重复元素;
- 在处理去重合并时,从测试结果来看,使用set集合效率较高。