Here you can find the source of capitalize(String string)
Parameter | Description |
---|---|
string | the string to capitalize. |
public static String capitalize(String string)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w . j a v a 2 s .c om * Converts the string to capitalized. Strings are of the format: THIS_IS_A_STRING, and the result of capitalization * would be ThisIsAString. * * @param string the string to capitalize. * @return the capitalized string. * @since 2.0 */ public static String capitalize(String string) { StringBuffer result = new StringBuffer(toCamelCase(string)); result.replace(0, 1, "" + Character.toUpperCase(result.charAt(0))); //$NON-NLS-1$ return result.toString(); } /** * Converts the string to camelcase. Strings are of the format: THIS_IS_A_STRING, and the result of camel casing * would be thisIsAString. * * @param string the string to be camelcased. * @return the camel cased string. * @since 2.0 */ public static String toCamelCase(String string) { StringBuffer result = new StringBuffer(string); while (result.indexOf("_") != -1) { //$NON-NLS-1$ int indexOf = result.indexOf("_"); //$NON-NLS-1$ result.replace(indexOf, indexOf + 2, "" + Character.toUpperCase(result.charAt(indexOf + 1))); //$NON-NLS-1$ } return result.toString(); } }