Example usage for java.util.stream Collectors minBy

List of usage examples for java.util.stream Collectors minBy

Introduction

In this page you can find the example usage for java.util.stream Collectors minBy.

Prototype

public static <T> Collector<T, ?, Optional<T>> minBy(Comparator<? super T> comparator) 

Source Link

Document

Returns a Collector that produces the minimal element according to a given Comparator , described as an Optional .

Usage

From source file:Main.java

public static void main(String[] args) {
    Stream<String> s = Stream.of("1", "2", "3");

    Optional<String> o = s.collect(Collectors.minBy(Comparator.reverseOrder()));

    if (o.isPresent()) {
        System.out.println(o.get());
    } else {/*from  w  ww . j ava 2  s  . c  o  m*/
        System.out.println("no value");
    }

}