Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comemnts

  1. Stream (introduced in Java 8) brings functional programming into Java so that coding in Java is easier and faster but at the cost of performance. Code written in Stream is slower than non-stream and lambda based Java code, generally speaking.

  2. The method Stream.map is not friendly on conversion to Arrays. Stream.mapToInt, Stream.mapToLong, etc. are better alternatives if you need to to convert a Stream object to an Array.

Stream.filter

8.0
7.0
5.0
null

Sum Integer Values

Taking Elements By Indexes

Convert a Stream to a Primitive Array

You can call the Stream.mapTo* method (NOT Stream.map) followed by Stream.toArray to convert a Stream to a primitive Array.

3
5
5
3
5
4
3
4
3
null

Calling Stream.map followed Stream.toArray cannot convert a Stream to a primitive array.

incompatible types: java.lang.Object[] cannot be converted to int[]
 int[] lens = Arrays.stream(words).map(word -> word.length()).toArray()
              ^                                                        ^ 

Convert A Stream to an Object Array

3
5
5
3
5
4
3
4
3
null