202. Creating a custom collector via Collector.of()
Creating a custom collector is a topic that we covered in detail in Chapter 9, Problem 193, of Java Coding Problem, First Edition. More precisely, in that problem, you saw how to write a custom collector by implementing the java.util.stream.Collector interface.
Don’t worry if you haven’t read that book/problem; you can still follow this problem. First, we will create several custom collectors. This time, we will rely on two Collector.of() methods that have the following signatures:
static <T,R> Collector<T,R,R> of(
  Supplier<R> supplier, 
  BiConsumer<R,T> accumulator, 
  BinaryOperator<R> combiner, 
  Collector.Characteristics... characteristics)
static <T,A,R> Collector<T,A,R> of(
  Supplier<A> supplier, 
  BiConsumer<A,T> accumulator, 
  BinaryOperator<A> combiner, 
  Function<A,R> finisher, 
  Collector.Characteristics... characteristics...