Java String Capitalize capitalize(final String input)

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

Description

Return the input string with the first character converted to upper case.

License

Open Source License

Parameter

Parameter Description
input the input; may be null or empty

Return

the input with the first character converted to upper case, or null (if input is null), or "" if input is ""

Declaration

public static String capitalize(final String input) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2013 compeople AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w  w  w  . ja  v a 2s. c  o m
 *    compeople AG - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Return the input string with the first character converted to upper case.
     * 
     * @param input
     *            the input; may be null or empty
     * @return the input with the first character converted to upper case, or
     *         null (if input is null), or "" if input is ""
     * 
     */
    public static String capitalize(final String input) {
        String result = input;
        if (input != null && input.length() > 0) {
            result = input.substring(0, 1).toUpperCase();
            if (input.length() > 1) {
                result += input.substring(1);
            }
        }
        return result;
    }
}

Related

  1. capitalizarPalabra(String palabra)
  2. capitalizarTexto(String texto)
  3. capitalize(CharSequence s)
  4. capitalize(CharSequence s)
  5. capitalize(final String docName)
  6. capitalize(final String name)
  7. capitalize(final String s)
  8. capitalize(final String s)
  9. capitalize(final String s)