Here you can find the source of longestCommonPrefix(String[] strs)
public static String longestCommonPrefix(String[] strs)
//package com.java2s; //License from project: Open Source License public class Main { public static String longestCommonPrefix(String[] strs) { if (null == strs || 0 == strs.length) return ""; String prefix = strs[0];/*from www . j a va 2s .c o m*/ for (int i = 0; i < strs.length; i++) { String str = strs[i]; int j = 0; for (j = 0; j < prefix.length(); j++) { if (j >= str.length() || prefix.charAt(j) != str.charAt(j)) break; } prefix = prefix.substring(0, j); } return prefix; } }