Example usage for java.util.stream IntStream findFirst

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

Introduction

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

Prototype

OptionalInt findFirst();

Source Link

Document

Returns an OptionalInt describing the first element of this stream, or an empty OptionalInt if the stream is empty.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(1, 2, 3, 4);
    OptionalInt n = i.findFirst();
    if (n.isPresent()) {
        System.out.println(n.getAsInt());
    } else {/*from ww  w . jav a 2 s  .co  m*/
        System.out.println("noValue");
    }
}