Guillaume Bailly wrote: Stream<String> ohMy = Stream.of("lions", "tigers", "bears"); Map<Integer, Optional<Character>> map = ohMy.collect( Collectors.groupingBy( String::length, Collectors.mapping(s -> s.charAt(0), Collectors.minBy(Comparator.naturalOrder())))); System.out.println(map); // {5=Optional[b], 6=Optional[t]} compile if change "s -> s.charAt(0) " to "(String s) -> s.charAt(0)"