Java String Upper Case toUpperCaseFirstAll(String text)

Here you can find the source of toUpperCaseFirstAll(String text)

Description

Changes the first character of all words in the given text to uppercase.

License

Open Source License

Parameter

Parameter Description
text the text to modify

Return

the text with all words capitalized

Declaration

public static String toUpperCaseFirstAll(String text) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//ww  w  . jav  a2 s.c  o m
     * Changes the first character of all words in the given text to uppercase.
     * 
     * @param text the text to modify
     * @return the text with all words capitalized
     */
    public static String toUpperCaseFirstAll(String text) {
        StringBuilder result = new StringBuilder();

        String[] words = text.split("\\s");

        for (int i = 0; i < words.length; i++) {
            result.append(toUpperCaseFirst(words[i]));

            if (i < words.length - 1) {
                result.append(" ");
            }
        }

        return result.toString();
    }

    /**
     * Changes the first character of the given text to upper case.
     * 
     * @param text the text which should be capitalized.
     * @return the capitalized text.
     */
    public static String toUpperCaseFirst(String text) {
        char[] charArray = text.toCharArray();
        charArray[0] = Character.toUpperCase(charArray[0]);
        return String.valueOf(charArray);
    }
}

Related

  1. toUpperCaseFirst(String str)
  2. toUpperCaseFirst(String str)
  3. toUpperCaseFirst(String str)
  4. toUpperCaseFirst(String text)
  5. toUpperCaseFirst(String text)
  6. toUpperCaseFirstChar(final String str)
  7. toUpperCaseFirstChar(String s)
  8. toUpperCaseFirstChar(String str)
  9. toUpperCaseFirstChar(String str)