Java String Decapitalize decapitalize(String string)

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

Description

Lowers the first letter of a String.

License

Open Source License

Parameter

Parameter Description
string the string to change

Return

the changed string

Declaration

public static String decapitalize(String string) 

Method Source Code

//package com.java2s;
/* Copyright 2010 - 2014 by Brian Uri!
       /*from  w w  w .j  a  v a 2 s .c  om*/
   This file is part of DDMSence.
       
   This library is free software; you can redistribute it and/or modify
   it under the terms of version 3.0 of the GNU Lesser General Public 
   License as published by the Free Software Foundation.
       
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
   GNU Lesser General Public License for more details.
       
   You should have received a copy of the GNU Lesser General Public 
   License along with DDMSence. If not, see <http://www.gnu.org/licenses/>.
    
   You can contact the author at ddmsence@urizone.net. The DDMSence
   home page is located at http://ddmsence.urizone.net/
 */

public class Main {
    /**
     * Lowers the first letter of a String. Silently does nothing if the string is null, empty, or not a letter.
     * 
     * @param string the string to change
     * @return the changed string
     */
    public static String decapitalize(String string) {
        if (isEmpty(string))
            return (string);
        if (string.length() == 1)
            return (string.toLowerCase());
        return (string.substring(0, 1).toLowerCase() + string.substring(1, string.length()));
    }

    /**
     * Checks if a String value is empty. An empty string is defined as one that is null, contains only whitespace, or
     * has length 0.
     * 
     * @param value the value to check.
     * @return a boolean, true if the value is null or zero-length, false otherwise
     */
    public static boolean isEmpty(String value) {
        return (value == null || value.trim().length() == 0);
    }
}

Related

  1. decapitalize(String s)
  2. decapitalize(String s)
  3. decapitalize(String st)
  4. decapitalize(String str)
  5. decapitalize(String string)
  6. decapitalize(String string)
  7. decapitalize(String string)
  8. decapitalize(String string)
  9. decapitalize(String text)