java stream limit items 1

java stream limit items

int maxNumberOfElements = 10;

list.stream()
    .limit(maxNumberOfElements); 

Here is what the above code is Doing:
1. We’re creating a stream from the list.
2. We’re limiting the stream to a maximum of 10 elements.
3. We’re printing the elements of the stream.

Similar Posts