IntStream limit(long maxSize) example

Description

IntStream limit(long maxSize) returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.

Syntax

limit has the following syntax.


IntStream limit(long maxSize)

Example

The following example shows how to use limit.


import java.util.stream.IntStream;
/*from   w ww  . j  av  a2s. co m*/
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder