Java String Capitalize capitalize(String input)

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

Description

Converts a string such that the first character is upper case.

License

Apache License

Parameter

Parameter Description
input the input string (possibly empty)

Return

the string with the first character converted from lowercase to upper case (may return the string unchanged if already capitalized)

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   www.j a v  a2s.  c  o  m
     * Converts a string such that the first character is upper case.
     * 
     * @param input the input string (possibly empty)
     * @return the string with the first character converted from lowercase to upper case (may
     * return the string unchanged if already capitalized)
     */

    public static String capitalize(String input) {
        if (input.length() == 0)
            return input;

        char ch = input.charAt(0);

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

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

Related

  1. capitalize(String input)
  2. capitalize(String input)
  3. capitalize(String input)
  4. capitalize(String input)
  5. capitalize(String input)
  6. capitalize(String inputString)
  7. capitalize(String line)
  8. capitalize(String membername)
  9. capitalize(String message)