Given:
What is the output?
Given:
What is the output?
The code creates and manipulates a stream of strings from a list of fruits. It uses intermediate operations (`peek` and `sorted`) and a terminal operation (`collect`). Intermediate operations are lazy and are only executed when the terminal operation is called. The first `peek` prints items in their original order: 'banana', 'orange', 'apple', 'lemon'. This is followed by a separator. After the list is sorted, the second `peek` prints the items in their sorted order: 'apple', 'banana', 'lemon', 'orange'. Then the final separator is printed, resulting in the printed output: banana orange apple lemon ----- apple banana lemon orange -----
Dis correct, until terminal operator is called the source won't generate streams.
C is correct
D is correct because only ----- print first and when collect is called execeute peek 1 (list in order original , sort , and peek2 (list ordered by natural order)
D is correct Tested
D is correct because Intermediate operations in a stream are lazy, meaning they are not evaluated until a terminal operation is invoked. The purpose of a terminal operation is to produce a result or perform a side effect.