IntStream limit(long maxSize)
returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.
limit
has the following syntax.
IntStream limit(long maxSize)
The following example shows how to use limit
.
import java.util.stream.IntStream; public class Main { public static void main(String[] args) { IntStream i = IntStream.of(6,5,7,1, 2, 3, 4); i.limit(3) .forEach(System.out::println); } }
The code above generates the following result.