Here you can find the source of longestCommonSubstring(String s[])
static public String longestCommonSubstring(String s[])
//package com.java2s; import java.util.*; public class Main { static public String longestCommonSubstring(String s[]) { if (s.length == 0) return ""; String res = s[0];/*from ww w.j ava 2 s .c o m*/ for (int i = 1; i < s.length; i++) { while (true) { if (s[i].startsWith(res)) break; if (res.length() == 0) return ""; res = res.substring(0, res.length() - 1); } } return res; } static public String longestCommonSubstring(Vector v) { if (v.size() == 0) return ""; String res = (String) v.elementAt(0); for (int i = 1; i < v.size(); i++) { while (true) { String s = (String) v.elementAt(i); if (s.startsWith(res)) break; if (res.length() == 0) return ""; res = res.substring(0, res.length() - 1); } } return res; } }