find String Common Prefix Length - Android java.lang

Android examples for java.lang:String Starts or Ends

Description

find String Common Prefix Length

Demo Code

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;

public class Main{

    private static int findCommonPrefixLength(CharSequence str1,
            CharSequence str2) {// w w w . ja va 2s .c om

        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 Tutorials