Java String Decapitalize decapitalize(String name)

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

Description

Utility method to take a string and convert it to normal Java variable name capitalization.

License

Apache License

Parameter

Parameter Description
name The string to be decapitalized.

Return

The decapitalized version of the string.

Declaration

public static String decapitalize(String name) 

Method Source Code

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

public class Main {
    /**/*w ww .ja va 2 s.c  om*/
     * Utility method to take a string and convert it to normal Java variable
     * name capitalization. This normally means converting the first character
     * from upper case to lower case, but in the (unusual) special case when
     * there is more than one character and both the first and second characters
     * are upper case, we leave it alone.
     * <p/>
     * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as
     * "URL".
     * 
     * @param name
     *            The string to be decapitalized.
     * @return The decapitalized version of the string.
     */
    public static String decapitalize(String name) {
        if (name.length() == 0) {
            return name;
        }
        if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))) {
            return name;
        }

        char chars[] = name.toCharArray();
        char c = chars[0];
        char modifiedChar = Character.toLowerCase(c);
        if (modifiedChar == c) {
            return name;
        }
        chars[0] = modifiedChar;
        return new String(chars);
    }
}

Related

  1. decapitalize(final String s)
  2. decapitalize(final String string)
  3. decapitalize(final String value)
  4. decapitalize(String name)
  5. decapitalize(String name)
  6. decapitalize(String name)
  7. decapitalize(String name)
  8. decapitalize(String name)