Here you can find the source of capitalize(final String s)
Parameter | Description |
---|---|
s | the original word |
public static String capitalize(final String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 LegSem./* w w w. j a v a 2 s. com*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * LegSem - initial API and implementation ******************************************************************************/ public class Main { /** * Capitalizes the first character of the specified string, * and de-capitalize the rest of characters. * * @param s the original word * @return the capitalized word */ public static String capitalize(final String s) { if (!isLower(s.charAt(0))) { return s; } StringBuilder sb = new StringBuilder(s.length()); sb.append(Character.toUpperCase(s.charAt(0))); sb.append(s.substring(1).toLowerCase()); return sb.toString(); } /** * Determine if character is lowercase. * * @param c the character to test * @return true if lower case */ protected static boolean isLower(final char c) { return c >= 'a' && c <= 'z' || Character.isLowerCase(c); } }