1

For the following pieces of code:

Block 1:

Stream.generate(() -> "abcd")
.filter(n -> n.length() == 4)
.limit(2)
.sorted()
.forEach(System.out::println);

Block 2:

Stream.generate(() -> "abc")
.filter(n -> n.length() == 4)
.limit(2)
.sorted()
.forEach(System.out::println);

I am trying to understand streams.

How does stream work internally? Does it always filter after producing one element ? Does limit also get fired after each element is generated ?

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
Adithya
  • 2,923
  • 5
  • 33
  • 47

0 Answers0