code: public static <T> Map<T, Long> countBy(Stream<T> stream) {
          return stream.collect(groupingBy(identity(), counting()));
      }
docs: Count by map.
  
  @param <T>    the type parameter
  @param stream the stream
  @return the map