Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
DoubleStream min() method in Java
The min() method of the DoubleStream class returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if this stream is empty.
The syntax is as follows:
OptionalDoublemin()
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 elements to the stream:
DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);
Get the maximum element from the DoubleStream:
OptionalDouble res = doubleStream.max();
The following is an example to implement DoubleStream min() method in Java:
Example
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
public class Demo {
public static void main(String[] args) {
DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);
OptionalDouble res = doubleStream.max();
System.out.println("Minimum element: ");
if (res.isPresent()) {
System.out.println(res.getAsDouble());
} else {
System.out.println("Nothing!");
}
}
}
Output
Minimum element: 95.8
Advertisements
