notes/pl/java/features/stream/streams.txt
Ihar Hancharenka df95a5c979 m
2025-02-10 12:10:41 +03:00

56 строки
1.7 KiB
Plaintext

http://stackoverflow.com/questions/32859038/java-8-list-to-map-with-stream
IntStreams:
http://www.deadcoderising.com/2015-05-19-java-8-replace-traditional-for-loops-with-intstreams/
Characteristics:
SIZED
SUBSIZED
SORTED
ORDERED
DISTINCT
NONNULL
IMMUTABLE
CONCURRENT
characterized by Spliterator
.trySplit()
.boxed()
???
.sorted()
full-barier operation (downstream ops can't start until this one ends)
.skip() and .limit()
does not preserve the stream size :(
.sublis() - is more effective
.parallell() stream really utilize Spliterator and do a HUGE perf-boost
.distinct()
.parallell().unordered() - can speed-up according to doc-n, but 10x slower than parallell and 3x to seq-l
.parallell.ordered and .parallell.unordered a just 2 distinct algos
.concat()
??? temporary or terminal
preserves SIZED if parts are SIZED
.flatMap()
like concat but better with ORDERED streams than .concat()
disadvantages (vs concat) are:
- no more speedup more than 2x using parallel
- don't preserves SIZED
- uses more memory
- short-circuiting (find result earlier than finishing consuming all the input)
- .flatMap...spliterator().tryAdvance() - throws OOM because of the buffering
https://www.youtube.com/watch?v=3qrNlWkJ3ac
! 25:14
List<String> result = List.of(List.of("foo", "bar"), List.of("baz", "...")).flatMap(List::stream).toList()
.orElseThrow(IllegalStateException::new)
Java9 stuff:
.ofNullable(System.getProperty("bla-bla"))
.takeWhile(predicate)
stops once a failed-to-match element found
.dropWhile(predicate)
-//- inverse
.iterate(3, x -> x < 100, x -> x + 3)
java9 adds a middle/second bound-parameter