Java String Uncapitalize uncapitalize(String string0)

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

Description

Safely uncapitalizes a string by converting the first character to lower case.

License

Apache License

Parameter

Parameter Description
string0 The string to uncapitalize

Return

A new string with the first character converted to lower case

Declaration

static public String uncapitalize(String string0) 

Method Source Code

//package com.java2s;
/*// w ww  .  jav a 2 s. c o  m
 * #%L
 * ch-commons-util
 * %%
 * Copyright (C) 2012 Cloudhopper by Twitter
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

public class Main {
    /**
     * Safely uncapitalizes a string by converting the first character to lower
     * case. Handles null, empty, and strings of length of 1 or greater.  For
     * example, this will convert "Joe" to "joe".  If the string is null, this
     * will return null.  If the string is empty such as "", then it'll just
     * return an empty string such as "".
     * @param string0 The string to uncapitalize
     * @return A new string with the first character converted to lower case
     */
    static public String uncapitalize(String string0) {
        if (string0 == null) {
            return null;
        }
        int length = string0.length();
        // if empty string, just return it
        if (length == 0) {
            return string0;
        } else if (length == 1) {
            return string0.toLowerCase();
        } else {
            StringBuilder buf = new StringBuilder(length);
            buf.append(string0.substring(0, 1).toLowerCase());
            buf.append(string0.substring(1));
            return buf.toString();
        }
    }
}

Related

  1. uncapitalize(String str)
  2. uncapitalize(String string)
  3. uncapitalize(String string)
  4. unCapitalize(String string)
  5. uncapitalize(String string)
  6. uncapitalize(String text)
  7. unCapitalizeClass(String className)
  8. uncapitalized(String aString)
  9. uncapitalizeFirstLetter(String s)