Java String Length Get lengthOfCommonPrefix(String s1, String s2)

Here you can find the source of lengthOfCommonPrefix(String s1, String s2)

Description

length Of Common Prefix

License

Open Source License

Declaration

private static int lengthOfCommonPrefix(String s1, String s2) 

Method Source Code

//package com.java2s;

public class Main {
    private static int lengthOfCommonPrefix(String s1, String s2) {
        if (s1 == null || s2 == null)
            return 0;
        int i = 0;
        for (; i < Math.min(s1.length(), s2.length()); ++i) {
            if (s1.charAt(i) != s2.charAt(i)) {
                break;
            }//w  w w .jav  a  2s. c  om
        }
        return i;
    }
}

Related

  1. lengthFormat(String str, int maxLength)
  2. lengthIfAllAlpha(String str)
  3. lengthIntegers(String str)
  4. lengthMinusColors(String thisStr)
  5. lengthMinusTrailingWhitespace(String line)
  6. lengthOfStartingWhitespace(String s)
  7. lengthOfString(final String cadena)
  8. lengthTokensField(String fieldName)
  9. lengthToString(double value, boolean proportional)