Here you can find the source of capitalize(String string)
public static String capitalize(String string)
//package com.java2s; /* Copyright (c) 2008 Charles Rich and Worcester Polytechnic Institute. * All Rights Reserved. Use is subject to license terms. See the file * "license.terms" for information on usage and redistribution of this * file and for a DISCLAIMER OF ALL WARRANTIES. */// w w w .j av a 2 s.c o m public class Main { /** * Return (possibly copy of) given string with first character upper case. */ public static String capitalize(String string) { if (Character.isUpperCase(string.charAt(0))) return string; char chars[] = string.toCharArray(); chars[0] = Character.toUpperCase(chars[0]); return new String(chars); } /** * Change first character of given string buffer to upper case. */ public static void capitalize(StringBuilder buffer) { if (buffer.length() > 0) { char first = buffer.charAt(0); if (!Character.isUpperCase(first)) buffer.setCharAt(0, Character.toUpperCase(first)); } } }