Java String Capitalize Word capitalizeFirsts(String word)

Here you can find the source of capitalizeFirsts(String word)

Description

capitalize Firsts

License

Open Source License

Declaration

public static String capitalizeFirsts(String word) 

Method Source Code

//package com.java2s;
/*//  w  w  w  .  j av a 2  s  .co  m
 * WANDORA
 * Knowledge Extraction, Management, and Publishing Application
 * http://wandora.org
 * 
 * Copyright (C) 2004-2016 Wandora Team
 * 
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * 
 *
 * GenericVelocityHelper.java
 *
 * Created on 17. joulukuuta 2004, 10:54
 */

public class Main {
    public static String capitalizeFirsts(String word) {
        StringBuffer newWord = new StringBuffer();
        boolean shouldCapitalize = true;
        if (word != null) {
            for (int i = 0; i < word.length(); i++) {
                if (Character.isLetter(word.charAt(i)) && shouldCapitalize) {
                    newWord.append(Character.toUpperCase(word.charAt(i)));
                    shouldCapitalize = false;
                } else if (!Character.isLetter(word.charAt(i))) {
                    newWord.append(word.charAt(i));
                    shouldCapitalize = true;
                } else
                    newWord.append(word.charAt(i));
            }
        }
        return newWord.toString();
    }
}

Related

  1. capitalizeFirstCharWords(String sentence)
  2. capitalizeFirstLetter(final String word)
  3. capitalizeFirstLetter(String word)
  4. capitalizeFirstLetterEachWord(String sentence)
  5. capitalizeFirstLetterWord(String word)
  6. capitalizeInitials(String words)
  7. capitalizeOneWord(String inputWord)
  8. capitalizeSingle(String word)
  9. capitalizeWord(String s)