Java Array Common Prefix longestCommonPrefix(String a, String b)

Here you can find the source of longestCommonPrefix(String a, String b)

Description

longest Common Prefix

License

Open Source License

Declaration

public static int longestCommonPrefix(String a, String b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int longestCommonPrefix(String a, String b) {
        int i = 0;
        char[] as = a.toCharArray();
        char[] bs = b.toCharArray();
        int aLen = as.length;
        int bLen = bs.length;
        while (i < aLen && i < bLen && as[i] == bs[i])
            ++i;//from   w w  w. j  av a2s  . c o m
        return i;
    }
}

Related

  1. longestCommonContiguousSubstring(String s, String t)
  2. longestCommonPath(String... paths)
  3. longestCommonPrefix(CharSequence str1, CharSequence str2)
  4. longestCommonPrefix(String one, String two)
  5. longestCommonPrefix(String s1, String s2)
  6. longestCommonPrefix(String str1, String str2)
  7. longestCommonPrefix(String... strs)