Android String Capitalize capitalize(String s)

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

Description

Capitalizes first character of the string

Parameter

Parameter Description
s input string

Return

capitalized string

Declaration

public static String capitalize(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w w w  .  ja  v  a 2  s  .  c  om
     * Capitalizes first character of the string
     * 
     * @param s
     *            input string
     * @return capitalized string
     */
    public static String capitalize(String s) {
        if (s == null || s.length() == 0) {
            return "";
        }
        char first = s.charAt(0);
        if (Character.isUpperCase(first)) {
            return s;
        } else {
            return Character.toUpperCase(first) + s.substring(1);
        }
    }
}

Related

  1. decapitalize(final String name)
  2. capitalize(String string)
  3. decapitalize(String string)
  4. capitalizeFirstLetter(String str)
  5. capitalize(String line)