public static int commonPrefix ( String text1 , String text2 ) { // Performance analysis: http://neil.fraser.name/news/2007/10/09/ int n = Math . min ( text1 . length ( ) , text2 . length ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( text1 . charAt ( i ) != text2 . charAt ( i ) ) { return i ; } } return n ; }
Determine the common prefix of two strings