Here you can find the source of longestCommonSubstring(final String s1, final String s2)
public static String longestCommonSubstring(final String s1, final String s2)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { public static String longestCommonSubstring(final String s1, final String s2) { for (int i = 0; i < s1.length() && i < s2.length(); i++) { if (s1.charAt(i) != s2.charAt(i)) { return s1.substring(0, i); }/* w w w. j a va 2 s .c om*/ } return s1.length() < s2.length() ? s1 : s2; } }