Java 8 Streams Java Java API
Interface:
java.util.stream.IntStream
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); } }
Output0 1 2 3 4
|