/*** @author 陈杨*/@SpringBootTest
@RunWith(SpringRunner.class)
public class CollectorsDetail {private List<String> names;private List<Student> students;private List<List<String>> snames;@Beforepublic void init() {names = Arrays.asList("Kirito", "Asuna", "Sinon", "Yuuki", "Alice");snames = Arrays.asList(Collections.singletonList("Kirito"), Collections.singletonList("Asuna"),Collections.singletonList("Sinon"), Collections.singletonList("Yuuki"),Collections.singletonList("Alice"));students = new Students().init();}@Testpublic void testCollectorsDetail() {

一、静态工厂类Collectors 实现方式

//    一、静态工厂类Collectors 实现方式//    Collectors 静态工厂类   最终由CollectorImpl实现
//       1、 通过CollectorImpl实现
//       2、 通过reducing()实现---> reducing()底层由CollectorImpl实现//    Collectors.toList()  是 Collectors.toCollection()的一种具化表现形式
//    Collectors.joining() 使用StringBuilder.append 拼接字符串

二、静态工厂类Collectors 常用收集器

//    二、静态工厂类Collectors 常用收集器/*返回一个(不可修改)unmodifiable List的ArrayList  按照相遇的顺序encounter order
@since 10
@SuppressWarnings("unchecked")
public static <T>Collector<T, ?, List<T>> toUnmodifiableList() {return new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,(left, right) -> { left.addAll(right); return left; },list -> (List<T>)List.of(list.toArray()),CH_NOID);
}*//*返回一个(不可修改)unmodifiable Set的HashSet 无序
@since 10
@SuppressWarnings("unchecked")
public static <T>Collector<T, ?, Set<T>> toUnmodifiableSet() {return new CollectorImpl<>((Supplier<Set<T>>) HashSet::new, Set::add,(left, right) -> {if (left.size() < right.size()) {right.addAll(left); return right;} else {left.addAll(right); return left;}},set -> (Set<T>)Set.of(set.toArray()),CH_UNORDERED_NOID);
}
*//*返回一个flatMapping扁平化mapper处理后 由downstream收集的 累加器处理的结果合并  单线程
@since 9
public static <T, U, A, R>Collector<T, ?, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper,Collector<? super U, A, R> downstream) {BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();return new CollectorImpl<>(downstream.supplier(),(r, t) -> {try (Stream<? extends U> result = mapper.apply(t)) {if (result != null)result.sequential().forEach(u -> downstreamAccumulator.accept(r, u));}},downstream.combiner(), downstream.finisher(),downstream.characteristics());
}*//*对符合Predicate预期结果 进行过滤filtering 使用downstream 收集元素
@since 9
public static <T, A, R>Collector<T, ?, R> filtering(Predicate<? super T> predicate,Collector<? super T, A, R> downstream) {BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();return new CollectorImpl<>(downstream.supplier(),(r, t) -> {if (predicate.test(t)) {downstreamAccumulator.accept(r, t);}},downstream.combiner(), downstream.finisher(),downstream.characteristics());
}*//*使用Map映射key-->keyMapper-->Key value-->valueMapper-->Value对映射后的结果进行组装entrySet-->Map<Key,Value> (unmodifiable Map)
@since 10
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T, K, U>Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ? extends K> keyMapper,Function<? super T, ? extends U> valueMapper) {Objects.requireNonNull(keyMapper, "keyMapper");Objects.requireNonNull(valueMapper, "valueMapper");return collectingAndThen(toMap(keyMapper, valueMapper),map -> (Map<K,U>)Map.ofEntries(map.entrySet().toArray(new Map.Entry[0])));
}*//*使用Map映射key-->keyMapper-->Key value-->valueMapper-->ValuemergeFunction 对相同key 映射后的进行Value 合并操作对映射后的结果进行组装entrySet-->Map<Key,Value> (unmodifiable Map)@since 10
@SuppressWarnings({"rawtypes", "unchecked"})
public static <T, K, U>Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ? extends K> keyMapper,Function<? super T, ? extends U> valueMapper,BinaryOperator<U> mergeFunction) {Objects.requireNonNull(keyMapper, "keyMapper");Objects.requireNonNull(valueMapper, "valueMapper");Objects.requireNonNull(mergeFunction, "mergeFunction");return collectingAndThen(toMap(keyMapper, valueMapper, mergeFunction, HashMap::new),map -> (Map<K,U>)Map.ofEntries(map.entrySet().toArray(new Map.Entry[0])));
}*/
//    Collectors 收集器
System.out.println("-----------------------------------------\n");//    使用ArrayList集合 按照流中元素排列先后顺序 进行添加操作
List<String> unmodifiableList = names.stream().collect(Collectors.toUnmodifiableList());
System.out.println(unmodifiableList);
System.out.println("---------------------------------------\n");//    使用HashSet集合 对流中元素顺序 进行添加操作
Set<String> unmodifiableSet = names.stream().collect(Collectors.toUnmodifiableSet());
System.out.println(unmodifiableSet);
System.out.println("---------------------------------------\n");//    将集合扁平化展开 对其中的字符串的每个字母 进行大写转换 使用ArrayList对转换后的结果进行收集
List<String> strings = snames.stream().collect(Collectors.flatMapping(list -> list.stream().map(String::toUpperCase), Collectors.toList()));
System.out.println(strings);
System.out.println("---------------------------------------\n");//    对流中元素进行遍历 对符合预期要求的元素 使用ArrayList集合存放
List<String> filteringPredicate = names.stream().collect(Collectors.filtering("Kirito"::equals,Collectors.toList()));
System.out.println(filteringPredicate);
System.out.println("---------------------------------------\n");//    对流中元素进行遍历  对key-->keyMapper value-->valueMapper 映射 得到Map集合
Map<Integer, List<Student>> listMap = students.stream().collect(Collectors.toUnmodifiableMap(Student::getId, student -> {List<Student> stus = new ArrayList<>();stus.add(student);return stus;}));System.out.println(listMap);
System.out.println("---------------------------------------\n");//    对流中元素进行遍历 对key-->keyMapper-->Key value-->valueMapper-->Value 映射
//    对满足相同Key的元素 Value进行合并
Map<Integer, String> lengthName = names.stream().collect(Collectors.toUnmodifiableMap(String::length,String::toString, (str1, str2) -> str1 + "\t" + str2));
System.out.println(lengthName);
System.out.println("---------------------------------------\n");

三、groupingBy分组

//    三、groupingBy分组//    分组 groupingBy//    对T元素按 key进行分组 --> 分组的依据 classifier--> 分组后的集合 value--> 得到 Map<key,value>
/*
Returns a {@code Collector} implementing a "group by" operation on
input elements of type {@code T}, grouping elements according to aclassification function, and returning the results in a {@code Map}.<p>The classification function maps elements to some key type {@code K}.
The collector produces a {@code Map<K, List<T>>} whose keys are the
values resulting from applying the classification function to the input
elements, and whose corresponding values are {@code List}s containing theinput elements which map to the associated key under the classification
function.<p>There are no guarantees on the type, mutability, serializability, or
thread-safety of the {@code Map} or {@code List} objects returned.*//*按照key对T进行classifier分组使用List集合收集分组结果  单线程 线程安全
public static <T, K> Collector<T, ?, Map<K, List<T>>>
groupingBy(Function<? super T, ? extends K> classifier) {return groupingBy(classifier, toList());
}*//*按照key对T进行classifier分组使用自定义收集器downstream 收集分组结果  单线程 线程安全
public static <T, K, A, D>Collector<T, ?, Map<K, D>> groupingBy(Function<? super T, ? extends K> classifier,Collector<? super T, A, D> downstream) {return groupingBy(classifier, HashMap::new, downstream);
}*//*按照key对T进行classifier分组使用自定义mapFactory  重置downstream的CollectorImpl实现使用自定义收集器downstream 收集分组结果  单线程 线程安全
public static <T, K, D, A, M extends Map<K, D>>
Collector<T, ?, M> groupingBy(Function<? super T, ? extends K> classifier,Supplier<M> mapFactory,Collector<? super T, A, D> downstream) {Supplier<A> downstreamSupplier = downstream.supplier();BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();BiConsumer<Map<K, A>, T> accumulator = (m, t) -> {K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");A container = m.computeIfAbsent(key, k -> downstreamSupplier.get());downstreamAccumulator.accept(container, t);};BinaryOperator<Map<K, A>> merger = Collectors.<K, A, Map<K, A>>mapMerger(downstream.combiner());@SuppressWarnings("unchecked")Supplier<Map<K, A>> mangledFactory = (Supplier<Map<K, A>>) mapFactory;//    不进行强制类型转换  重构CollectorImpl实现if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {return new CollectorImpl<>(mangledFactory, accumulator, merger, CH_ID);}else {//    进行强制类型转换  重构CollectorImpl实现@SuppressWarnings("unchecked")Function<A, A> downstreamFinisher = (Function<A, A>) downstream.finisher();Function<Map<K, A>, M> finisher = intermediate -> {intermediate.replaceAll((k, v) -> downstreamFinisher.apply(v));@SuppressWarnings("unchecked")M castResult = (M) intermediate;return castResult;};return new CollectorImpl<>(mangledFactory, accumulator, merger, finisher, CH_NOID);}
}*/
//    分组
System.out.println("-----------------------------------------\n");//    select * from students group by sex ;
Map<String, List<Student>> sexStudent =students.stream().collect(Collectors.groupingBy(Student::getSex));
System.out.println(sexStudent);
System.out.println("-----------------------------------------\n");//    select sex, count(*) from students group by sex ;
Map<String, Long> sexCount =students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.counting()));
System.out.println(sexCount);
System.out.println("-----------------------------------------\n");//    select sex,avg(salary) from students group by sex ;
Map<String, Double> avgSexSalary = students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.averagingDouble(Student::getSalary)));
System.out.println(avgSexSalary);
System.out.println("-----------------------------------------\n");//    嵌套分组  先根据sex分组 再对结果按照addr进行分组
Map<String, Map<String, List<Student>>> NestedGroupBy = students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.groupingBy(Student::getAddr)));
System.out.println(NestedGroupBy);
System.out.println("-----------------------------------------\n");//    使用自定义收集器downstream 按性别分组  使用HashSet进行 结果收集
Map<String, HashSet<Student>> sexHashSet = students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.toCollection(HashSet::new)));
System.out.println(sexHashSet);
System.out.println("-----------------------------------------\n");//    使用自定义收集器downstream 按性别分组  使用HashSet进行 结果收集  重置CollectorImpl实现
Map<String, HashSet<Student>> sexCustomCollectorImpl = students.stream().collect(Collectors.groupingBy(Student::getSex, Hashtable::new, Collectors.toCollection(HashSet::new)));
System.out.println(sexCustomCollectorImpl);
System.out.println("-----------------------------------------\n");

四、groupingByConcurrent分组

 //    四、groupingByConcurrent分组//    分组 groupingByConcurrent//    流的适用条件://          无序 Collector.Characteristics.UNORDERED//          并发 Collector.Characteristics.CONCURRENT//    This is a {@link Collector.Characteristics#CONCURRENT concurrent} and//    {@link Collector.Characteristics#UNORDERED unordered} Collector./*按照key对T进行classifier分组使用List集合收集分组结果public static <T, K>Collector<T, ?, ConcurrentMap<K, List<T>>>groupingByConcurrent(Function<? super T, ? extends K> classifier) {return groupingByConcurrent(classifier,  ::new, toList());}*//*按照key对T进行classifier分组使用自定义收集器downstream 收集分组结果
public static <T, K, A, D>Collector<T, ?, ConcurrentMap<K, D>> groupingByConcurrent(Function<? super T, ? extends K> classifier,Collector<? super T, A, D> downstream) {return groupingByConcurrent(classifier, ConcurrentHashMap::new, downstream);}*//*按照key对T进行classifier分组使用自定义累加器mapFactory  重置downstream的CollectorImpl实现使用自定义收集器downstream 收集分组结果public static <T, K, A, D, M extends ConcurrentMap<K, D>>Collector<T, ?, M> groupingByConcurrent(Function<? super T, ? extends K> classifier,Supplier<M> mapFactory,Collector<? super T, A, D> downstream) {Supplier<A> downstreamSupplier = downstream.supplier();BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();BinaryOperator<ConcurrentMap<K, A>> merger = Collectors.<K, A, ConcurrentMap<K, A>>mapMerger(downstream.combiner());@SuppressWarnings("unchecked")Supplier<ConcurrentMap<K, A>> mangledFactory = (Supplier<ConcurrentMap<K, A>>) mapFactory;BiConsumer<ConcurrentMap<K, A>, T> accumulator;if (downstream.characteristics().contains(Collector.Characteristics.CONCURRENT)) {accumulator = (m, t) -> {K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");A resultContainer = m.computeIfAbsent(key, k -> downstreamSupplier.get());downstreamAccumulator.accept(resultContainer, t);};}else {accumulator = (m, t) -> {K key = Objects.requireNonNull(classifier.apply(t), "element cannot be mapped to a null key");A resultContainer = m.computeIfAbsent(key, k -> downstreamSupplier.get());//  多个操作-->同时操作同一个结果容器-->同一时间,有且只有一个进行实际操作-->线程同步synchronized (resultContainer) {downstreamAccumulator.accept(resultContainer, t);}};}if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {return new CollectorImpl<>(mangledFactory, accumulator, merger, CH_CONCURRENT_ID);}else {@SuppressWarnings("unchecked")Function<A, A> downstreamFinisher = (Function<A, A>) downstream.finisher();Function<ConcurrentMap<K, A>, M> finisher = intermediate -> {intermediate.replaceAll((k, v) -> downstreamFinisher.apply(v));@SuppressWarnings("unchecked")M castResult = (M) intermediate;return castResult;};return new CollectorImpl<>(mangledFactory, accumulator, merger, finisher, CH_CONCURRENT_NOID);}}*/
//    分组 无序 并发
System.out.println("-----------------------------------------\n");//    按性别分组  使用ArrayList进行 结果收集
ConcurrentMap<String, List<Student>> sexStudentConcurrent = students.stream().collect(Collectors.groupingByConcurrent(Student::getSex));
System.out.println(sexStudentConcurrent);
System.out.println("-----------------------------------------\n");//    使用自定义收集器downstream 按性别分组  使用HashSet进行 结果收集
ConcurrentMap<String, HashSet<Student>> sexHashSetConcurrent = students.stream().collect(Collectors.groupingByConcurrent(Student::getSex, Collectors.toCollection(HashSet::new)));
System.out.println(sexHashSetConcurrent);
System.out.println("-----------------------------------------\n");//    使用自定义收集器downstream 按性别分组  使用HashSet进行 结果收集  重置CollectorImpl实现
ConcurrentReferenceHashMap<String, HashSet<Student>> sexCustomCollectorImplConcurrent =students.stream().collect(Collectors.groupingByConcurrent(Student::getSex,ConcurrentReferenceHashMap::new, Collectors.toCollection(HashSet::new)));
System.out.println(sexCustomCollectorImplConcurrent);
System.out.println("-----------------------------------------\n");

五、partitioningBy分区

//    五、partitioningBy分区//  分区  partitioningBy/*对满足预期的条件 进行分区 使用ArrayList 进行结果的收集
public static <T>Collector<T, ?, Map<Boolean, List<T>>> partitioningBy(Predicate<? super T> predicate) {return partitioningBy(predicate, toList());
}*//*对满足预期的条件 进行分区 使用自定义收集器downstream 进行结果的收集
public static <T, D, A>Collector<T, ?, Map<Boolean, D>> partitioningBy(Predicate<? super T> predicate,Collector<? super T, A, D> downstream) {BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();BiConsumer<Partition<A>, T> accumulator = (result, t) ->downstreamAccumulator.accept(predicate.test(t) ? result.forTrue : result.forFalse, t);BinaryOperator<A> op = downstream.combiner();BinaryOperator<Partition<A>> merger = (left, right) ->new Partition<>(op.apply(left.forTrue, right.forTrue),op.apply(left.forFalse, right.forFalse));Supplier<Partition<A>> supplier = () ->new Partition<>(downstream.supplier().get(),downstream.supplier().get());if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {return new CollectorImpl<>(supplier, accumulator, merger, CH_ID);}else {Function<Partition<A>, Map<Boolean, D>> finisher = par ->new Partition<>(downstream.finisher().apply(par.forTrue),downstream.finisher().apply(par.forFalse));return new CollectorImpl<>(supplier, accumulator, merger, finisher, CH_NOID);}
}*/
        //    分区System.out.println("-----------------------------------------\n");//    select * from students partition by (addr == Sword Art Online) ;Map<Boolean, List<Student>> addrPartition = students.stream().collect(Collectors.partitioningBy(student -> student.getAddr().equals("Sword Art Online")));System.out.println(addrPartition);System.out.println("-----------------------------------------\n");//    嵌套分区  先根据sex分区 再对结果按照addr进行分区Map<Boolean, Map<Boolean, List<Student>>> NestedPartiton = students.stream().collect(Collectors.partitioningBy(student -> student.getSex().equals("Male"),Collectors.partitioningBy(student -> student.getAddr().equals("Sword Art Online"))));System.out.println(NestedPartiton);System.out.println("-----------------------------------------\n");//    使用自定义downstream收集器分区Map<Boolean, HashSet<Student>> addrCustomPartition = students.stream().collect(Collectors.partitioningBy(student -> student.getAddr().equals("Sword Art Online"), Collectors.toCollection(HashSet::new)));System.out.println(addrCustomPartition);System.out.println("-----------------------------------------\n");}}

六、测试结果

  .   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v2.1.2.RELEASE)2019-02-20 16:58:15.870  INFO 13392 --- [           main] c.j.d.java8.Stream.CollectorsDetail      : Starting CollectorsDetail on DESKTOP-87RMBG4 with PID 13392 (started by 46250 in E:\IdeaProjects\design)
2019-02-20 16:58:15.871  INFO 13392 --- [           main] c.j.d.java8.Stream.CollectorsDetail      : No active profile set, falling back to default profiles: default
2019-02-20 16:58:16.383  INFO 13392 --- [           main] c.j.d.java8.Stream.CollectorsDetail      : Started CollectorsDetail in 0.708 seconds (JVM running for 1.421)
-----------------------------------------[Kirito, Asuna, Sinon, Yuuki, Alice]
---------------------------------------[Yuuki, Asuna, Kirito, Sinon, Alice]
---------------------------------------[KIRITO, ASUNA, SINON, YUUKI, ALICE]
---------------------------------------[Kirito]
---------------------------------------{5=[Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], 4=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8)], 3=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8)], 2=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], 1=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
---------------------------------------{6=Kirito, 5=Asuna    Sinon    Yuuki    Alice}
--------------------------------------------------------------------------------{Female=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------{Female=4, Male=1}
-----------------------------------------{Female=9.99999999E8, Male=9.99999999E8}
-----------------------------------------{Female={Alicization=[Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], Sword Art Online=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Gun Gale Online=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8)], Alfheim Online=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8)]}, Male={Sword Art Online=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}}
-----------------------------------------{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
----------------------------------------------------------------------------------{Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)], Female=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)]}
-----------------------------------------{Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)], Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------{Female=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)], Male=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
----------------------------------------------------------------------------------{false=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8), Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------{false={false=[Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8)]}, true={false=[], true=[Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}}
-----------------------------------------{false=[Student(id=4, name=Yuuki, sex=Female, age=15, addr=Alfheim Online, salary=9.99999999E8), Student(id=3, name=Sinon, sex=Female, age=16, addr=Gun Gale Online, salary=9.99999999E8), Student(id=5, name=Alice, sex=Female, age=14, addr=Alicization, salary=9.99999999E8)], true=[Student(id=2, name=Asuna, sex=Female, age=17, addr=Sword Art Online, salary=9.99999999E8), Student(id=1, name=Kirito, sex=Male, age=18, addr=Sword Art Online, salary=9.99999999E8)]}
-----------------------------------------

Stream流与Lambda表达式(三) 静态工厂类Collectors相关推荐

  1. Stream流与Lambda表达式(一) 杂谈

    一.流 转换为数组.集合 package com.java.design.java8.Stream;import org.junit.Test; import org.junit.runner.Run ...

  2. stream流及lambda表达式快速总结

    前言: 内容: stream流是对集合迭代器的增强,使得对集合可以进行高效的聚合操作(过滤,排序.统计分组)或者大批量数据操作,stream流中用到了lambda表达式进行高效率代码书写.lambda ...

  3. Java Stream 流常用方法 lambda 表达式实现交集、并集、差集、去重复并集等

    一般的javaList 交.并集采用简单的 removeAll retainAll 等操作,不过这也破坏了原始的javaList对象,采用java8 lambda表达式流操作则可以不影响原始list对 ...

  4. 使用Java8新特性(stream流、Lambda表达式)实现多个List 的笛卡尔乘积 返回需要的List<JavaBean>

    需求分析: 有两个Long类型的集合 : List<Long> tagsIds; List<Long> attributesIds; 现在需要将这两个Long类型的集合进行组合 ...

  5. Stream流和Lambda表达式遍历HashMap

    Map<String,Object> map = new HashMap<>();map.put("name","zhongxu");m ...

  6. Stream流与Lambda表达式(四) 自定义收集器

    一.自定义SetCustomCollector收集器 package com.java.design.Stream.CustomCollector;import java.util.*; import ...

  7. Java8新特性概览——Stream特性,Lambda表达式,函数式接口Function、Predicate、Consumer,方法引用等概述

    概述: Java 8 新特性概述:https://www.ibm.com/developerworks/cn/java/j-lo-jdk8newfeature/index.html JAVA8 十大新 ...

  8. LeetCode 905 Sort Array By Parity--Java stream,Python lambda表达式一行 解法

    题目地址:Sort Array By Parity - LeetCode Given an array A of non-negative integers, return an array cons ...

  9. Java 8流和Lambda表达式–解析文件示例

    最近,我想从输出日志中提取某些数据. 这是日志文件的一部分: 2015-01-06 11:33:03 b.s.d.task [INFO] Emitting: eVentToRequestsBolt _ ...

最新文章

  1. ASP.NET Web API 路由对象介绍
  2. python进阶项目设计_推荐系统进阶:设计和构建推荐系统流程综述(1)
  3. samba 问题Windows能看到文件夹但是不能打开(路径写错了)
  4. IOS中货币高精度要求使用NSDecialNumber、
  5. shell循环和分支
  6. 【九】Git 可视化GUI管理工具 - SourceTree
  7. codeforce 460B Little Dima and Equation
  8. 太平洋电脑城 GHOST XP SP3 快速装机版 V9.8
  9. 计算机桌面文件为何不能剪贴,复制粘贴,详细教您电脑复制粘贴不能用了怎么解决...
  10. Unity-CharacterController(角色控制器)
  11. Word怎么转换成PDF?Speedpdf批量免费在线转换
  12. Error: Index .kibana belongs to a version of Kibana that cannot be automatically migrated. Reset it
  13. 安装ie9提示未能完成安装_win7系统安装Ie提示“Internet explorer未能完成安装”的解决方法...
  14. 简析项目中常用的七参数转换法和四参数转换法以及涉及到的基本测量学知识...
  15. 简单好用的二级区域选择控件
  16. 导入训练好的模型参数代码报错Failed to find any matching files for ram://20787ba9-e8c3-4c71-a3b9-dc406d492e95/varia
  17. unit自动驾驶怎么使用_高速公路开启“无人驾驶”模式,自动驾驶功能真是这么用的吗?...
  18. Android应用的界面编程
  19. FPGA(五)RTL代码之一(跨时钟域设计)
  20. 传奇大神何恺明被曝回归学界,网友:要成全MIT引用最高的人了

热门文章

  1. 绝症老父亲即将说不了话,儿子用AI技术挽留他的声音
  2. 【安骑士】安装失败问题分析
  3. Squid配置二级代理(父代理)
  4. 用 TensorFlow 目标检测 API 发现皮卡丘!
  5. 【Linux基础】作业二
  6. 序列化与字符流的操作
  7. TestBird频现国内手游“盛宴” 开发商互相介绍用得很赞
  8. jquery 设置checkbox的checked属性 总是出问题
  9. PHP文件头部(header)解释
  10. Linux视频教程系列汇总