Let's say I have a Stream of Strings called s
. Is it possible to have a unary operation that converts every lone String to two Strings?
So if the original Stream contains {a,b,c}
and the operation converts every single String s
to s + "1"
and s + "2"
then we would get: {a1,a2,b1,b2,c1,c2}
.
Is this possible (with a lambda expression)?
Yes, you can use
flatMap
likeExample:
Output: