Java String Capitalize Full capitalizeFully(String input)

Here you can find the source of capitalizeFully(String input)

Description

capitalize Fully

License

Open Source License

Declaration

public static String capitalizeFully(String input) 

Method Source Code

//package com.java2s;
/*/*  w  w w  . ja  v a2s.c  o m*/
 *  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 <https://www.gnu.org/licenses/>.
 */

public class Main {
    public static String capitalizeFully(String input) {
        if (input == null)
            return null;

        String s = input.toLowerCase();

        int strLen = s.length();
        StringBuffer buffer = new StringBuffer(strLen);
        boolean capitalizeNext = true;
        for (int i = 0; i < strLen; i++) {
            char ch = s.charAt(i);

            if (Character.isWhitespace(ch)) {
                buffer.append(ch);
                capitalizeNext = true;
            } else if (capitalizeNext) {
                buffer.append(Character.toTitleCase(ch));
                capitalizeNext = false;
            } else {
                buffer.append(ch);
            }
        }
        return buffer.toString();
    }
}

Related

  1. capitalizeFully(String input, String delimiters)
  2. capitalizeFully(String str)
  3. capitalizeFully(String str)
  4. capitalizeFully(String str)