Here you can find the source of capitalize(String str)
public static String capitalize(String str)
//package com.java2s; /*/* w w w .j av a 2 s . c o m*/ * (c) Copyright 2010-2011 AgileBirds * * This file is part of OpenFlexo. * * OpenFlexo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * OpenFlexo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { public static String capitalize(String str) { if (isAlpha(str.charAt(0))) { return str.substring(0, 1).toUpperCase() + str.substring(1); } else // if starts with '_' for example, capitalize 2nd character return str.charAt(0) + str.substring(1, 2).toUpperCase() + str.substring(2); } /** * Returns true if ch matches [A-Za-z] http://www.asciitable.com * * @param ch * @return */ public static boolean isAlpha(char ch) { // returns true if ch matches [A-Za-z] return ((ch > (char) 64 && ch < (char) 91) || (ch > (char) 96 && ch < (char) 123)); } }