Capitalize first word

This example will show how to capitalize the letter of a word using straight up java. Thanks to our friends over at PBS kids, we borrowed a phrase from Super why! theme song. We want to capitalize the 'W' in the who and we can do this by calling Character.toUpperCase passing in the first character of the string. To combine the rest of the string we can concatenate the string by substring the superWhyLyrics phrase with a starting index of 1 as we don't want want to include the 'W' twice.

Straight up Java

Capitalize first letter

public void capitalize_first_letter_of_sentence () { 
    String superWhyLyrics = "who’s got the power? The power to read.";
    String sentenceStartsWithCapital = Character
            .toUpperCase(superWhyLyrics.charAt(0)) + superWhyLyrics.substring(1);
    assertEquals("Who’s got the power? The power to read.", sentenceStartsWithCapital);