DoubleStream findAny() example

Description

DoubleStream findAny() returns an OptionalDouble describing some element of the stream, or an empty OptionalDouble if the stream is empty. This is a short-circuiting terminal operation.

Syntax

findAny has the following syntax.


OptionalDouble findAny()

Example

The following example shows how to use findAny.


import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
//w  w w .  j  a v  a2s. co  m
public class Main {
  public static void main(String[] args) {
    DoubleStream b = DoubleStream.of(1.1,2.2,3.3,4.4,5.5);
    OptionalDouble d = b.findAny();
    if(d.isPresent()){
      System.out.println(d.getAsDouble());
    }else{
      System.out.println("no data");
    }    
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




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