

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LongStream max() method in Java
The max() method of the LongStream class in Java returns an OptionalLong describing the maximum element of this stream, or an empty optional if this stream is empty.
The syntax is as follows
OptionalLong max()
Here, OptionalLong is a container object which may or may not contain a long value.
To use the LongStream class in Java, import the following package
import java.util.stream.LongStream;
The following is an example to implement LongStream max() method in Java. The isPresent() method of the OptionalLong class returns true if the value is present
Example
import java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(20000L, 15000L, 11000L, 74000L, 50000L); // Get the maximum element OptionalLong res = longStream.max(); System.out.println("Maximum element..."); if (res.isPresent()) { System.out.println(res.getAsLong()); } else { System.out.println("Nothing!"); } } }
Output
Maximum element... 74000
- Related Questions & Answers
- LongStream noneMatch() method in Java
- LongStream filter() method in Java
- LongStream forEach() method in Java
- LongStream rangeClosed() method in Java
- LongStream peek() method in Java
- LongStream empty() method in Java
- LongStream findFirst() method in Java
- LongStream of() method in Java
- LongStream anyMatch() method in Java
- LongStream toArray() method in Java
- LongStream summaryStatistics() method in Java
- LongStream boxed() method in Java
- LongStream sorted() method in Java
- LongStream asDoubleStream() method in Java
- LongStream skip() method in Java
Advertisements