Java String Capitalize Word capitalizeWord(String s)

Here you can find the source of capitalizeWord(String s)

Description

Capitalises the first letter of a given string.

License

Open Source License

Parameter

Parameter Description
s the input string

Return

the capitalized string

Declaration

public static String capitalizeWord(String s) 

Method Source Code

//package com.java2s;
/*/*from  ww w. j a v  a 2  s.  c om*/
 Copyright (C) 2010 by
 * 
 *    Cam-Tu Nguyen 
 *  ncamtu@ecei.tohoku.ac.jp or ncamtu@gmail.com
 *
 *  Xuan-Hieu Phan  
 *  pxhieu@gmail.com 
 *
 *  College of Technology, Vietnamese University, Hanoi
 *    Graduate School of Information Sciences, Tohoku University
 *
 * JVnTextPro-v.2.0 is a 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 2 of the License,
 * or (at your option) any later version.
 *
 * JVnTextPro-v.2.0 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  JVnTextPro-v.2.0); if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

public class Main {
    /**
     * Capitalises the first letter of a given string.
     *  
     * @param s  the input string
     * 
     * @return   the capitalized string
     */
    public static String capitalizeWord(String s) {
        // validate
        if ((s == null) || (s.length() == 0)) {
            return s;
        }
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
    }
}

Related

  1. capitalizeFirstLetterWord(String word)
  2. capitalizeFirsts(String word)
  3. capitalizeInitials(String words)
  4. capitalizeOneWord(String inputWord)
  5. capitalizeSingle(String word)
  6. capitalizeWord(String s)
  7. capitalizeWord(String str)
  8. capitalizeWord(String word)
  9. capitalizeWord(String word)