Close

Java 8 Streams - IntStream.max Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

OptionalInt max()

Returns an OptionalInt describing the maximum element of this stream, or an empty optional if this stream is empty. This is a special case of a reduction.

Examples


package com.logicbig.example.intstream;

import java.util.stream.IntStream;

public class MaxExample {

public static void main(String... args) {
IntStream intStream = IntStream.range(1, 5);
int i = intStream.max().orElse(-1);
System.out.println(i);
}
}

Output

4




See Also