Close

Java 8 Streams - IntStream.limit Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

IntStream limit(long maxSize)

This intermediate operation returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.

This is a short-circuiting stateful operation.

Examples


package com.logicbig.example.intstream;

import java.util.stream.IntStream;

public class LimitExample {

public static void main(String... args) {
IntStream stream = IntStream.iterate(0, i -> i + 1)
.limit(5);
stream.forEach(System.out::println);
}
}

Output

0
1
2
3
4




See Also