Java String Decapitalize decapitalize(String string)

Here you can find the source of decapitalize(String string)

Description

Decapitalize a String if it begins with a capital letter, e.g.: FooBar -> fooBar

License

Open Source License

Parameter

Parameter Description
string a String

Return

a decapitalized String

Declaration

public static String decapitalize(String string) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w  w w. j a va2  s.  co m*/
     * Decapitalize a String if it begins with a capital letter, e.g.:
     * FooBar -> fooBar
     *
     * @param string a String
     * @return a decapitalized String
     */
    public static String decapitalize(String string) {
        char c0 = string.charAt(0);
        if (!Character.isUpperCase(c0)) {
            return string;
        }
        if (string.length() > 1 && Character.isUpperCase(string.charAt(1))) {
            return string;
        }
        char[] chars = string.toCharArray();
        chars[0] = Character.toLowerCase(c0);
        return new String(chars);
    }
}

Related

  1. decapitalize(String s)
  2. decapitalize(String st)
  3. decapitalize(String str)
  4. decapitalize(String string)
  5. decapitalize(String string)
  6. decapitalize(String string)
  7. decapitalize(String string)
  8. decapitalize(String text)
  9. decapitalize(String word)