Java String Capitalize capitalize(String input)

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

Description

Capitalizes the input string, converting the first character to upper case.

License

Apache License

Parameter

Parameter Description
input a non-empty string

Return

the same string if already capitalized, or a capitalized version

Declaration

public static String capitalize(String input) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from   ww  w .  j  a  va 2 s  . c om
     * Capitalizes the input string, converting the first character to upper case.
     *
     * @param input a non-empty string
     * @return the same string if already capitalized, or a capitalized version
     */
    public static String capitalize(String input) {
        char first = input.charAt(0);

        if (Character.isUpperCase(first))
            return input;

        return String.valueOf(Character.toUpperCase(first))
                + input.substring(1);
    }
}

Related

  1. capitalize(String in)
  2. capitalize(String in)
  3. capitalize(String input)
  4. capitalize(String input)
  5. capitalize(String input)
  6. capitalize(String input)
  7. capitalize(String input)
  8. capitalize(String input)
  9. capitalize(String input)