Java String Uncapitalize uncapitalize(String str)

Here you can find the source of uncapitalize(String str)

Description

Uncapitalize a String, changing the first letter to lower case as per Character#toLowerCase(char) .

License

Open Source License

Parameter

Parameter Description
str the String to uncapitalize, may be <code>null</code>

Return

the uncapitalized String, null if null

Declaration

public static String uncapitalize(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  w  w . jav a  2 s  . c  om
     * Uncapitalize a <code>String</code>, changing the first letter to
     * lower case as per {@link Character#toLowerCase(char)}.
     * No other letters are changed.
     * @param str the String to uncapitalize, may be <code>null</code>
     * @return the uncapitalized String, <code>null</code> if null
     */
    public static String uncapitalize(String str) {
        return changeFirstCharacterCase(str, false);
    }

    private static String changeFirstCharacterCase(String str, boolean capitalize) {
        if (str == null || str.length() == 0) {
            return str;
        }
        StringBuilder sb = new StringBuilder(str.length());
        if (capitalize) {
            sb.append(Character.toUpperCase(str.charAt(0)));
        } else {
            sb.append(Character.toLowerCase(str.charAt(0)));
        }
        sb.append(str.substring(1));
        return sb.toString();
    }
}

Related

  1. uncapitalize(String str)
  2. uncapitalize(String str)
  3. uncapitalize(String str)
  4. uncapitalize(String str)
  5. uncapitalize(String str)
  6. uncapitalize(String str)
  7. uncapitalize(String str)
  8. uncapitalize(String str)
  9. uncapitalize(String str)