Here you can find the source of uncapitalize(String str)
Parameter | Description |
---|---|
str | the String to uncapitalize, may be null |
public static String uncapitalize(String str)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j a va2 s .c o m*/ * Uncapitalize a {@code String}, changing the first letter to lower case as per {@link Character#toLowerCase(char)}. No other letters are changed. * * @param str the {@code String} to uncapitalize, may be {@code null} * @return the uncapitalized {@code String}, or {@code null} if the supplied string is {@code 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; } else { char baseChar = str.charAt(0); char updatedChar; if (capitalize) { updatedChar = Character.toUpperCase(baseChar); } else { updatedChar = Character.toLowerCase(baseChar); } if (baseChar == updatedChar) { return str; } char[] chars = str.toCharArray(); chars[0] = updatedChar; return new String(chars, 0, chars.length); } } }