0

I have name String : abc edf

i want to display fist letter of the all word in capital like : Abc Edf

how to do it ?

Joseph Mekwan
  • 1,082
  • 1
  • 15
  • 28

2 Answers2

1

Check org.apache.commons.lang.WordUtils

https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/WordUtils.html

Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
0

As mentioned in the comments, there are many answers to this question. Just for fun I wrote my own method real quick. Feel free to use it and/or improve it:

public static String capitalizeAllWords(String str) {
    String phrase = "";
    boolean capitalize = true;
    for (char c : str.toLowerCase().toCharArray()) {
        if (Character.isLetter(c) && capitalize) {
            phrase += Character.toUpperCase(c);
            capitalize = false;
            continue;
        } else if (c == ' ') {
            capitalize = true;
        }
        phrase += c;
    }
    return phrase;
}

Test:

String str = "this is a test message";
System.out.print(capitalizeAllWords(str));

Output:

This Is A Test Message
Jared Rummler
  • 37,824
  • 19
  • 133
  • 148