spliterator

Understanding Spliterator, Collector and Stream in Java 8

回眸只為那壹抹淺笑 提交于 2019-11-28 13:48:20
问题 I am having trouble understanding the Stream interface in Java 8, especially where it has to do with the Spliterator and Collector interfaces. My problem is that I simply can't understand yet the Spliterator and the Collector interfaces, and as a result the Stream interface is still somewhat obscure to me. What exactly is a Spliterator and a Collector , and how can I use them? If I am willing to write my own Spliterator or Collector (and probably my own Stream in that process), what should I

Why overload the varargs method of() in Java Stream interface?

烂漫一生 提交于 2019-11-28 12:24:17
The Stream interface has two overloads for the method of() . One of these is a variable-arity method while the other takes a single argument. Is the single-argument method a performance optimization versus passing one argument to the variable-arity method? If so, how does it improve performance? The same questions could be asked of the empty() method, which would seem to be syntax sugar around the variable-arity of() . I see that the implementation differs between these methods, with the difference apparently being how the Spliterator is instantiated; but what advantage does this offer to the

Understanding deeply spliterator characteristics

人盡茶涼 提交于 2019-11-27 11:32:38
In order to try to deeply understand java streams and spliterators, I have some subtle questions about spliterator characteristics : Q1: Stream.empty() vs Stream.of() (Stream.of() without args) Stream.empty() : SUBSIZED, SIZED Stream.of() : SUBSIZED, IMMUTABLE , SIZED, ORDERED Why Stream.empty() doesn't have the same characteristics of Stream.of() ? Note that it has impacts when using in conjunction with Stream.concat() (specially not having ORDERED ). I would say that Stream.empty() should have not just IMMUTABLE and ORDERED but also DISTINCT and NONNULL . Also it make sense Stream.of() with