Java String Capitalize capitalize(String s)

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

Description

Capitalizes the first letter (and only the first!) of the string.

License

Open Source License

Parameter

Parameter Description
s The string to capitalize.

Declaration

public static final String capitalize(String s) 

Method Source Code

//package com.java2s;
/**/*  w w w.j  a  v a  2s  . co  m*/
 * Copyright (c) 2009-2011, The HATS Consortium. All rights reserved.
 * This file is licensed under the terms of the Modified BSD License.
 */

public class Main {
    /**
     * Capitalizes the first letter (and only the first!) of the string.
     *
     * If the string is empty, it returns the same string; otherwise,
     * returns a copy of the string with the first letter capitalized.
     *
     * @param s The string to capitalize.
     */
    public static final String capitalize(String s) {
        if (s == null || s.length() == 0)
            return s;

        return Character.toUpperCase(s.charAt(0)) + s.substring(1);
    }
}

Related

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