int (String a, String b, Comparator stringComparator) { int max = Math.min(a.length(), b.length()); for (int i = 0; i < max; i++) { char f = a.charAt(i); char s = b.charAt(i); if ((f != s) && (stringComparator.compare(String.valueOf(f), String.valueOf(s)) != 0)) { return i; } } return max; }