小结本文探究了stream的实现原理,介绍了怎么用java 8 stream的开源框架 streamex来解答stackoverflow上一些经常被问到关于java 8 stream的问题:
Convert Java 8
ListintoMap
用JDK Stream API:
Mapresult = choices.stream().collect(Collectors.toMap(Choice::getName, Function.identity()));
用StreamEx API:
Mapresult = StreamEx.of(choices).toMap(Choice::getName);
-
Custom thread pool in Java 8 parallel stream
立即学习“Java免费学习笔记(深入)”;
用JDK Stream API:
ForkJoinPool forkJoinPool = new ForkJoinPool(2);
forkJoinPool.submit(() ->
//parallel task here, for example
IntStream.range(1, 1_000_000).parallel().filter(PrimesPrint::isPrime).collect(toList())
).get();用StreamEx API:
IntStreamEx.range(1, 1_000_000).parallel(new ForkJoinPool(2))
.filter(PrimesPrint::isPrime).toList();Java 8 Distinct by property
用JDK Stream API:
public staticPredicate distinctByKey(Function super T, ?> keyExtractor) { Set
用StreamEx API:
StreamEx.of(persons).distinctBy(Person::getName);
Is it possible to cast a Stream in Java 8?
用JDK Stream API:
Stream.of(objects)
.filter(Client.class::isInstance)
.map(Client.class::cast)
.map(Client::getID)
.forEach(System.out::println);用StreamEx API:
StreamEx.of(objects)
.select(Client.class)
.map(Client::getID)
.forEach(System.out::println);相关文章:
相关视频:











