java集合工具类
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;public class CollUtil {/*** 集合是否为空** @param collection 集合* @return 是否为空*/public static boolean isEmpty(Collection<?> collection) {return collection == null || collection.isEmpty();}/*** 集合是否为非空** @param collection 集合* @return 是否为非空*/public static boolean isNotEmpty(Collection<?> collection) {return false == isEmpty(collection);}/*** 集合是否为非空 --> 执行* @param collection* @param consumer* @param <T>*/public static <T> void isNotEmpty(Collection<T> collection, Consumer<Collection<T>> consumer){if(isNotEmpty(collection)){consumer.accept(collection);}}/*** 集合是否为非空 --> 执行* @param collection* @param consumer* @param <T>*/public static <T> void isNotEmptyList(List<T> collection, Consumer<List<T>> consumer){if(isNotEmpty(collection)){consumer.accept(collection);}}/*** 集合是否为空 --> 执行* @param collection* @param consumer* @param <T>*/public static <T> void isEmpty(Collection<T> collection, Consumer<Collection<T>> consumer){if(isEmpty(collection)){consumer.accept(collection);}}/*** 集合是否为空 --> 执行* @param collection* @param consumer* @param <T>*/public static <T> void isEmptyList(List<T> collection, Consumer<List<T>> consumer){if(isEmpty(collection)){consumer.accept(collection);}}/*** 去重 返回新集合* @param collection* @return* @param <T>*/public static <T> List<T> distinct(List<T> collection){return collection.stream().distinct().collect(Collectors.toList());}
}