Implementing Mutable Reduction: The collect() Method The collect(Collector) method accepts a collector that encapsulates the functions required to perform a…