Java String Capitalize All capitalizeAllWords(String text)

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

Description

Capitalizes all words in a string

License

Open Source License

Parameter

Parameter Description
text the original string

Return

altered string

Declaration

public static String capitalizeAllWords(String text) 

Method Source Code

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

public class Main {
    /**/*from ww  w .ja  v a  2s  .  c  o m*/
     * Capitalizes all words in a string
     * @param text the original string
     * @return altered string
     */
    public static String capitalizeAllWords(String text) {
        String[] Split = text.split("_");

        String Out = "";

        for (int i = 0; i < Split.length; i++) {
            Out += capitalize(Split[i]);

            if (i < Split.length) {
                Out += "_";
            }
        }

        return Out;
    }

    /**
     * Capitalize on single word
     * @param word the word
     * @return capitalized word
     */
    public static String capitalize(String word) {
        String FirstLetter = word.substring(0, 1);
        return FirstLetter.toUpperCase() + word.substring(1);
    }
}

Related

  1. capitaliseAllWords(String str)
  2. capitalizeAll(final String value)
  3. capitalizeAll(String string)
  4. capitalizeAll(String text)
  5. capitalizeAllFirstChar(String text)
  6. capitalizeAllWords(String words)