做网站开店,wordpress摘要插件,公司注册网上怎样注册,网站建设选择云主机吗一、场景#xff1a;
二、结论#xff1a;
1. 四种方法耗时
三、代码#xff1a; 一、场景#xff1a;
求差集 List1 - Lsit2 二、结论#xff1a;
1. 四种方法耗时
初始条件方法名方法思路耗时 List1.size319418 List2.size284900 List..removeAll(Lsit2)1036987ms…一、场景
二、结论
1. 四种方法耗时
三、代码 一、场景
求差集 List1 - Lsit2 二、结论
1. 四种方法耗时
初始条件方法名方法思路耗时 List1.size319418 List2.size284900 List..removeAll(Lsit2)1036987msremoveAll_01List.contains()614859msremoveAll_02运用Set 150ms推荐removeAll_03用Set.contains()再优化112ms推荐 三、代码
package com.privatecloud.core.util.collections;import com.alibaba.fastjson2.JSON;
import com.privatecloud.core.util.file.FileIOUtil;
import com.privatecloud.core.util.file.FilesReadUtil;
import com.privatecloud.core.util.file.FilesUtil;
import lombok.extern.slf4j.Slf4j;import java.io.IOException;
import java.util.*;Slf4j
public class ListUtilsT {public ListT removeAll_01(ListT source, ListT destination) {ListT result new LinkedListT();for (T t : source) {if (!destination.contains(t)) {result.add(t);}}return result;}/*** 2运用Set可以去重这一特性。效率有明显提升** param source* param destination* return*/public ListT removeAll_02(ListT source, ListT destination) {ListT result new LinkedListT();MapT, Integer sourceMap new HashMapT, Integer();for (T t : source) {if (sourceMap.containsKey(t)) { //原集合中的重复值sourceMap.put(t, sourceMap.get(t) 1);} else {sourceMap.put(t, 1);}}SetT all new HashSetT(destination);for (Map.EntryT, Integer entry : sourceMap.entrySet()) {T key entry.getKey();Integer value entry.getValue();if (all.add(key)) {for (int i 0; i value; i) {result.add(key);}}}return result;}/*** 3用Set.contains()再优化** param source* param destination* return*/public ListT removeAll_03(ListT source, ListT destination) {ListT result new LinkedListT();SetT destinationSet new HashSetT(destination);for (T t : source) {if (!destinationSet.contains(t)) {result.add(t);}}return result;}}