- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream findAny() method in Java
The findAny() method of the DoubleStream class returns an OptionalDouble describing some element of the stream, or an empty OptionalDouble if the stream is empty.
The syntax is as follows
OptionalDouble findAny()
Here, OptionalDouble is a container object which may or may not contain a double value To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create a DoubleStream and add some elements
DoubleStream doubleStream = DoubleStream.of(23.8, 30.2, 50.5, 78.9, 80.4, 95.8);
Now, display an element
OptionalDouble res = doubleStream.findAny();
The following is an example to implement DoubleStream findAny() method in Java
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(23.8, 30.2, 50.5, 78.9, 80.4, 95.8); OptionalDouble res = doubleStream.findAny(); if (res.isPresent()) System.out.println(res.getAsDouble()); else System.out.println("Nothing!"); } }
Output
23.8
Advertisements