code: public static Collector<CharSequence, ?, String> commonPrefix() {
          return Collectors.collectingAndThen(
              Collectors.reducing((CharSequence s1, CharSequence s2) -> {
                  if (s1 == null || s2 == null)
                      return "";
  
                  int l = Math.min(s1.length(), s2.length());
                  int i;
                  for (i = 0; i < l && s1.charAt(i) == s2.charAt(i); i++);
  
                  return s1.subSequence(0, i);
              }),
              s -> s.map(Objects::toString).orElse("")
          );
      }
docs: Get a {@link Collector} that calculates the common prefix of a set of strings.