public static Collector<CharSequence, ?, String> commonPrefix() {
        return collectingAndThen(
            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("")
        );
    }
Get a {@link Collector} that calculates the common prefix of a set of strings.
jOOL/src/main/java/org/jooq/lambda/Agg.java