How can you use flatMap to filter a stream? - Cracking the Java Coding Interview #java

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 119: How can you use flatMap to filter a stream?
Рекомендации по теме
Комментарии
Автор

we should use flatmap when we want have even empty or the result value instead of optional
because the try catch that you maid can be done on the map also and then there is no difference

sofianerebib
Автор

I still don't understand the mechanism. Flatmap returns a new Stream instance for each element of the original stream? You have a Stream of Streams? 😕

MrVankog
Автор

Is the empty stream not a singleton? I mean it does the same regardless of its type and has no state. It should be a singleton.

redcrafterlppa
Автор

What happened to Java Isn't Strict Type

shahirofficial
Автор

Exception processing is very expensive and it is not recommended for a regular control flow. May be better using a filter with 'isNumber' function instead.

akalexus...
Автор

Anyone but me hurts when seeing such try-catch in a stream :(.
The problem with map this it is just a Function which does not care about the nullable/error.
I see the better approach just use stream.map().filter()
Just flatMap() here just a workaround

xutiTrinh
Автор

Title of this video is misleading. (you can also "return null;" instead of "return Stream.of();")

almazglaz