Java String uncapitalize

Introduction

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

No other letters are changed.

uncapitalize(null)  = null
uncapitalize("")    = ""
uncapitalize("Cat") = "cat"
uncapitalize("CAT") = "cAT"
public class Main{
    public static void main(String[] argv) throws Exception{
        String str = "Demo2s.com";
        System.out.println(uncapitalise(str));
    }//from  w w w  .ja  v a 2 s. c o m

    public static String uncapitalise(String str) {
        return uncapitalize(str);
    }
    public static String uncapitalize(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        return new StringBuffer(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1))
                .toString();
    }
   
}



PreviousNext

Related