Android CharSequence Search findCommonPrefixLength(CharSequence str1, CharSequence str2)

Here you can find the source of findCommonPrefixLength(CharSequence str1, CharSequence str2)

Description

find Common Prefix Length

Declaration

private static int findCommonPrefixLength(CharSequence str1,
            CharSequence str2) 

Method Source Code

//package com.java2s;

public class Main {
    private static int findCommonPrefixLength(CharSequence str1,
            CharSequence str2) {/*from w  ww.  j  a v a2s.c o m*/

        int length = (Math.min(str1.length(), str2.length()));
        for (int i = 0; i < length; i++) {
            if (str1.charAt(i) != str2.charAt(i)) {
                return i;
            }
        }

        return 0;

    }
}

Related

  1. findCommonSuffixLength(CharSequence str1, CharSequence str2, int commonPrefixLength)
  2. indexOfDifference(CharSequence cs1, CharSequence cs2)