Here you can find the source of capitalizeFirstLetter(final String aString)
Parameter | Description |
---|---|
aString | the string to convert to Title case |
public static String capitalizeFirstLetter(final String aString)
//package com.java2s; /*// w w w . j a v a2 s. c o m * Copyright 2002 (C) Bryan McRoberts <merton_monk@yahoo.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * */ public class Main { /** * Capitalize the first letter of every word in a string * * @param aString * the string to convert to Title case * @return a new string with the first letter of every word capitalised */ public static String capitalizeFirstLetter(final String aString) { boolean toUpper = true; final char[] a = aString.toLowerCase().toCharArray(); for (int i = 0; i < a.length; ++i) { if (Character.isWhitespace(a[i])) { toUpper = true; } else { if (toUpper && Character.isLowerCase(a[i])) { a[i] = Character.toUpperCase(a[i]); } toUpper = false; } } return new String(a); } }