Android CharSequence Search indexOfDifference(CharSequence cs1, CharSequence cs2)

Here you can find the source of indexOfDifference(CharSequence cs1, CharSequence cs2)

Description

index Of Difference

License

Apache License

Declaration

public static int indexOfDifference(CharSequence cs1, CharSequence cs2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static final int INDEX_NOT_FOUND = -1;

    public static int indexOfDifference(CharSequence cs1, CharSequence cs2) {
        if (cs1 == cs2) {
            return INDEX_NOT_FOUND;
        }//  ww  w .  j  a v a 2  s. co  m
        if (cs1 == null || cs2 == null) {
            return 0;
        }
        int i;
        for (i = 0; i < cs1.length() && i < cs2.length(); ++i) {
            if (cs1.charAt(i) != cs2.charAt(i)) {
                break;
            }
        }
        if (i < cs2.length() || i < cs1.length()) {
            return i;
        }
        return INDEX_NOT_FOUND;
    }
}

Related

  1. findCommonPrefixLength(CharSequence str1, CharSequence str2)
  2. findCommonSuffixLength(CharSequence str1, CharSequence str2, int commonPrefixLength)