Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 465 Bytes

File metadata and controls

34 lines (24 loc) · 465 Bytes

Limit:

It restricts the stream to the first n elements and ignores the rest.

List<Integer> numbers = List.of(1, 2, 3, 4, 5);

List<Integer> result = numbers.stream()
        .limit(3)
        .toList();

System.out.println(result);

Output:

[1, 2, 3]

Previous: F Peek

Next: H Skip