Here you can find the source of capitalize(String string)
Parameter | Description |
---|---|
string | the string |
public static String capitalize(String string)
//package com.java2s; /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ public class Main { /**// ww w . j ava 2 s . c o m * Capitalize the first letter of a string. If the string is empty, just return an empty string; * if it is null, return a null string. string. * * @param string the string * @return {@code p_string} with the first letter capitalized */ public static String capitalize(String string) { if (string == null) { return null; } else if (string.length() == 0) { return string; } else { char[] chars = string.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return new String(chars); } } }