static int commonPrefixLength(String a, String b) { int i = 0; while (i < a.length && i < b.length && a[i] == b[i]) { i++; } return i; }