Here you can find the source of capitalize(String s)
public static String capitalize(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 UCLA Medical Imaging Informatics Group * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html ******************************************************************************/ public class Main { public static String capitalize(String s) { // Capitalize only the first character of the string... if (s == null) return new String(); switch (s.length()) { case 0://from www. j ava 2s .c om return new String(); case 1: return s.toUpperCase(); default: String lowerSubstring = s.substring(1).toLowerCase(); String upperSubstring = s.substring(0, 1).toUpperCase(); return new String(upperSubstring + lowerSubstring); } } }