~/devreads

#stream

5 posts

10 Jan 2023

30 Sept 2019

lukaseder 1 min read

One of the Stream APIs greatest features is its laziness. The whole pipeline is constructed lazily, stored as a set of instructions, akin to a SQL execution plan. Only when we invoke a terminal operation, the pipeline is started. It is still lazy, meaning that some operations may be short circuited. Some third party libraries … Continue reading A Quick…

javajava 8lazystream

3 Jul 2017

lukaseder 1 min read

Notice, this issue has been fixed in Java 8 (8u222), thanks for the comment Zheka Kozlov In a recent article, I’ve shown that programmers should always apply a filter first, map later strategy with streams. The example I made there was this one: In this case, the limit() operation implements the filtering, which should take … Continue reading Are Java…

java 8flatmaplazy processinglazy streamstream

29 Jun 2017

lukaseder 1 min read

In recent days, I’ve seen a bit too much of this: Something is very wrong with the above example. Can you see it? No? Let me rename those variables for you. Better now? Exactly. The above algorithm is O(N) when it could be O(1): (Let’s assume the lack of explicit ordering is irrelevant) I’m working … Continue reading A Basic…

javasqlalgorithmic complexityperformancestream

29 Mar 2016

lukaseder 1 min read

An interesting question by Tagir Valeev on Stack Overflow has recently caught my attention. To keep things short (read the question for details), while the following code works: printing 1 2 3 4 5 The following, similar code won’t work: Causing a StackOverflowError. Sure, this kind of recursive iteration is not optimal. It wasn’t prior … Continue reading Watch Out…

javajava 8java 9lambda expressionstream