本文借助Java8的Stream API完成ArrayList集合运算:求交集、并集和差集!
public class CollectionUtil {/*** 判断为空*/public static boolean isEmpty(Collection> collection) {return (collection == null || collection.isEmpty());}/*** 判断非空*/public static boolean isNotEmpty(Collection> collection) {return !isEmpty(collection);}/*** 求交集** @param masterList 主数据列表* @param slaveList 从数据列表* @param * @return*/public static List getIntersection(List masterList, List slaveList) {return masterList.stream().filter(slaveList::contains).collect(Collectors.toList());}/*** 求差集** @param masterList 主数据列表* @param slaveList 从数据列表* @param * @return*/public static List getDifferenceSet(List masterList, List slaveList) {return masterList.stream().filte