Skip to content

Tag: java-stream

Invokedynamic with non-static context

I learnt that invokedynamic instruction of bytecode calls a static method representation of lambda. Please let me know if that is incorrect. if correct, then how is below code working? Answer It’s not correct to say that lambda expressions were always compiled to a static method. It’s not specified, how they …

Java 8 Streams Remove Duplicate Letter

I’m trying to apply my knowledge of streams to some leetcode algorithm questions. Here is a general summary of the question: Given a string which contains only lowercase letters, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in l…

How to filter and log null objects in Java 8 streams

I am trying to wrap my head around java8 streams and was wondering if someone can help me with it. In old java, Basically, I want to filter null objects and also log it. What’s a good way to do this in java 8? Answer You can use peek and put an if statement inside it: But this kind of