Linked Questions
10 questions linked to/from Understanding deeply spliterator characteristics
198 votes
9 answers
62k views
Should I return a Collection or a Stream?
Suppose I have a method that returns a read-only view into a member list: class Team { private List<Player> players = new ArrayList<>(); // ... public List<Player> ...
83 votes
7 answers
61k views
Most efficient way to get the last element of a stream
Stream doesn't have a last() method: Stream<T> stream; T last = stream.last(); // No such method What's the most elegant and/or efficient way to get the last element (or null for an empty ...
36 votes
5 answers
4k views
Is this a bug in Files.lines(), or am I misunderstanding something about parallel streams?
Environment: Ubuntu x86_64 (14.10), Oracle JDK 1.8u25 I try and use a parallel stream of Files.lines() but I want to .skip() the first line (it's a CSV file with a header). Therefore I try and do ...
5 votes
1 answer
6k views
Understanding sequential vs parallel stream spliterators in Java 8 and Java 9
A question about spliterators that at first glance is not straightforward. In streams, .parallel() changes the behaviour that the stream is processed. However I was expecting the spliterators created ...
5 votes
1 answer
3k views
What's the time complexity of Java Stream distinct().sorted()?
Every time when I get a coding interview, I always avoid using Java stream, because I can't analyze the time complexity very well. For example: in my daily work, I might write like this: Arrays.stream(...
2 votes
2 answers
971 views
Why Hashmap.values().parallelStream() does not run in parallel while wrap them in ArrayList could work?
The hashmap has two key and value pairs, they are not processed in parallel by different threads. import java.util.stream.Stream; import java.util.Map; import java.util.HashMap; class Ideone { ...
4 votes
2 answers
145 views
EnumSet.spliterator without characteristic Spliterator.NONNULL
I was thinking about an answer to the question: How to test for null keys on any Java map implementation? My first thought was to check if the Spliterator of the keyset of a map has the ...
4 votes
1 answer
163 views
Does stream use CHARACTERISTICS of the stream source?
from this question a spliterator reporting either, IMMUTABLE or CONCURRENT, is guaranteed to never throw a ConcurrentModificationException. Of course, CONCURRENT precludes SIZED ...
5 votes
0 answers
179 views
Why .flatMap() is so inefficient (non lazy)? [duplicate]
After the first question about understanding deeply java streams spliterators here, another subtle question about streams: Why the implementation of .flatMap() in Java is so inefficient (non lazy)? ...
3 votes
0 answers
40 views
Spliterator SORTED characteristic behaviour [duplicate]
Spliterator interface defines a number of characteristics: A Spliterator also reports a set of characteristics() of its structure, source, and elements from among ORDERED, DISTINCT, SORTED, SIZED, ...