Here you can find the source of uncapitalize(CharSequence cs)
Uncapitalizes a CharSequence changing the first letter to title case as per Character#toLowerCase(char) .
Parameter | Description |
---|---|
cs | the String to uncapitalize, may be null |
null
if null String input
public static String uncapitalize(CharSequence cs)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 MadRobot./* w w w. j a va 2 s. c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Elton Kent - initial API and implementation ******************************************************************************/ public class Main { /** * <p> * Uncapitalizes a CharSequence changing the first letter to title case as * per {@link Character#toLowerCase(char)}. No other letters are changed. * </p> * * <p> * For a word based algorithm, see * {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}. A * <code>null</code> input String returns <code>null</code>. * </p> * * <pre> * StringUtils.uncapitalize(null) = null * StringUtils.uncapitalize("") = "" * StringUtils.uncapitalize("Cat") = "cat" * StringUtils.uncapitalize("CAT") = "cAT" * </pre> * * @param cs * the String to uncapitalize, may be null * @return the uncapitalized String, <code>null</code> if null String input * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String) * @see #capitalize(CharSequence) */ public static String uncapitalize(CharSequence cs) { if (cs == null) { return null; } int strLen; if ((strLen = cs.length()) == 0) { return cs.toString(); } return new StringBuilder(strLen).append(Character.toLowerCase(cs.charAt(0))).append(subSequence(cs, 1)) .toString(); } /** * Gets a CharSequence length or <code>0</code> if the CharSequence is * <code>null</code>. * * @param cs * a CharSequence or <code>null</code> * @return CharSequence length or <code>0</code> if the CharSequence is * <code>null</code>. */ public static int length(CharSequence cs) { return cs == null ? 0 : cs.length(); } /** * Returns a new <code>CharSequence</code> that is a subsequence of this * sequence starting with the <code>char</code> value at the specified * index. The length (in <code>char</code>s) of the returned sequence is * <code>length() - start</code>, so if <code>start == end</code> then an * empty sequence is returned. </p> * * @param cs * the specified subsequence, may be null * @param start * the start index, inclusive * @return a new subsequence or null * * @throws IndexOutOfBoundsException * if <code>start</code> is negative or if <code>start</code> is * greater than <code>length()</code> */ public static CharSequence subSequence(CharSequence cs, int start) { return cs == null ? null : cs.subSequence(start, cs.length()); } }