Here you can find the source of lengthOfCommonPrefix(String s1, String s2)
private static int lengthOfCommonPrefix(String s1, String s2)
//package com.java2s; public class Main { private static int lengthOfCommonPrefix(String s1, String s2) { if (s1 == null || s2 == null) return 0; int i = 0; for (; i < Math.min(s1.length(), s2.length()); ++i) { if (s1.charAt(i) != s2.charAt(i)) { break; }//w w w .jav a 2s. c om } return i; } }