Example usage for java.util.stream IntStream limit

List of usage examples for java.util.stream IntStream limit

Introduction

In this page you can find the example usage for java.util.stream IntStream limit.

Prototype

IntStream limit(long maxSize);

Source Link

Document

Returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.iterate(1, n -> n + 1);
    i.limit(10).forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(6, 5, 7, 1, 2, 3, 4);
    i.limit(3).forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {

    int[] numbers = { 2, 3, 5, 7, 11, 13 };
    IntStream intStream = Arrays.stream(numbers);
    intStream = intStream.limit(3);
    System.out.println(intStream.sum());
}

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.generate(() -> {
        return (int) (Math.random() * 100);
    });// w w w . ja  v  a2  s .  c om
    i.limit(10).forEach(System.out::println);
}