Java String Capitalize capitalize(String str)

Here you can find the source of capitalize(String str)

Description

Capitalize the first character in the string if necessary.

License

Open Source License

Declaration

public static String capitalize(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w  w  .  j  a  v  a 2s . com*/
     * Capitalize the first character in the string if necessary.
     */
    public static String capitalize(String str) {
        if (str == null) {
            return str;
        }
        int strLen = str.length();
        if (strLen == 0) {
            return str;
        }
        char first = Character.toTitleCase(str.charAt(0));
        if (first == str.charAt(0)) {
            return str;
        }
        return new StringBuilder(strLen).append(first).append(str.substring(1)).toString();
    }
}

Related

  1. capitalize(String s, String fullstring)
  2. capitalize(String source)
  3. capitalize(String src)
  4. capitalize(String str)
  5. capitalize(String str)
  6. capitalize(String str)
  7. capitalize(String str)
  8. capitalize(String str)
  9. capitalize(String str)