WordUtil { public static String longestCommonSubstring(String word1, String word2) { int start = 0; int max = 0; for (int i = 0; i < word1.length(); i++) { for (int j = 0; j < word2.length(); j++) { int x = 0; while (word1.charAt(i + x) == word2.charAt(j + x)) { x++; if (((i + x) >= word1.length()) || ((j + x) >= word2.length())) { break; } } if (x > max) { max = x; start = i; } } } return word1.substring(start, (start + max)); }  static String removeSurrounding(final String token); static boolean isAlphaNumberic(String str); static boolean isMixedCase(String str); static boolean isUpperAlphaNumberic(String str); static boolean isAlphabetic(String str); static boolean hasVowel(String str); static boolean hasConsonant(String str); static boolean hasVowelAndConsonant(String str); static boolean hasCharacter(String str, String matchChars); static boolean hasTrailingCharacter(String str, String matchChars); static boolean hasTrailingPuncuation(String str); static int countLeadChar(String str, char matchChar); static boolean startsWithCharacter(String str, String matchChars); static String compactRepeatedChars(String str); static String toUnicode(String str); static String toDecimal(String str); static boolean hasNumber(String str); static boolean hasLetter(String str); static boolean hasCapital(String str); static boolean startsWithCapital(String str); static boolean hasAllCapitals(String str); static String getCapital(String seq); static String capitalize(String str, char[] wordDelimiters); static String capitalizeTitle(String str); static String capitalizeTitle(String str, char[] wordDelimiters); static boolean hasWord(String segment, Collection<String> stopwords); static boolean hasWord(String segment, String wordDelimiters, Collection<String> stopwords); static boolean hasWord(StringTokenizer tokenizer, Collection<String> stopwords); static boolean hasLeadWord(String segment, Collection<String> stopwords, boolean caseSensative); static boolean hasLeadWord(String segment, String wordDelimiters, Collection<String> stopwords,
			boolean caseSensative); static boolean hasLeadWord(StringTokenizer tokenizer, Collection<String> stopwords, boolean caseSensative); static int countWords(String segment, char[] wordDelimiters); static String initials(String segment); static String initials(String segment, char[] wordDelimiters); static String longestCommonSubstring(String word1, String word2);  }
@Test public void longestCommonSubstringTest() { String longestCommon = WordUtil.longestCommonSubstring("Local Area Network Connection", "Local Area Network"); assertEquals("Local Area Network", longestCommon); String longestCommon1 = WordUtil.longestCommonSubstring("Ethernet Local Area Network Connection", "Local Area Network"); assertEquals("Local Area Network", longestCommon1); String longestCommon2 = WordUtil.longestCommonSubstring("Ethernet Local Area Network Connection", "123"); assertEquals("", longestCommon2); }