Java String Capitalize First capitalizeFirst(String s)

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

Description

Returns the specified string, with the first character capitalized.

License

Open Source License

Parameter

Parameter Description
s the input string

Return

the output string

Declaration

public static String capitalizeFirst(String s) 

Method Source Code

//package com.java2s;
/**/*from ww  w  .j a  va  2 s  . c  om*/
 * Copyright (c) 2011 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */

public class Main {
    /**
     * Returns the specified string, with the first character capitalized.
     * Returns null/empty if the argument is null/empty.
     * @param s the input string
     * @return the output string
     */
    public static String capitalizeFirst(String s) {
        if (s == null) {
            return null;
        } else if (s.isEmpty()) {
            return s;
        } else {
            return Character.toUpperCase(s.charAt(0)) + s.substring(1);
        }
    }
}

Related

  1. capitalizedLetter(String str, boolean onlyFirst)
  2. capitalizeFirst(String attribute)
  3. capitalizeFirst(String input)
  4. capitalizeFirst(String name)
  5. capitalizeFirst(String rawStr)
  6. capitalizeFirst(String str)
  7. capitalizeFirst(String str)
  8. capitalizeFirst(String str)
  9. capitalizeFirst(String str)