Java String Capitalize capitalize(String input)

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

Description

Capitalizes first character in given string

License

Apache License

Parameter

Parameter Description
input to capitalize first character

Return

capitalized string or null if null

Declaration

public static String capitalize(String input) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   ww w.ja  va2s  .  c  o m
     * Capitalizes first character in given string
     *
     * @param input to capitalize first character
     * @return capitalized string or null if null
     */
    public static String capitalize(String input) {

        if (input == null) {
            return null;
        }

        if (input.length() > 1) {
            for (int i = 0; i < input.length(); i++) {
                if (Character.isAlphabetic(input.charAt(i))) {
                    return input.substring(0, i)
                            + Character.toString(input.charAt(i))
                                    .toUpperCase() + input.substring(i + 1);
                }
            }
        }

        return input.toUpperCase();
    }
}

Related

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