Convert String into Title Case

前端 未结 9 1290
终归单人心
终归单人心 2021-01-03 15:09

I am a beginner in Java trying to write a program to convert strings into title case. For example, if String s = \"my name is milind\", then the output should b

9条回答
  •  时光说笑
    2021-01-03 16:04

    You want to change the case of the first letter of each word of a String.

    To do so, I would follow the following steps :

    • split the String in words : see String.split(separator)
    • retrieve the first letter of each word : see String.charAt(index)
    • retrieve its capitalized version : the Character.toUpperCase(char) you use is perfect
    • concatenate the capitalized letter with the rest of the word : concatenation operator (+) and String.substring
    • create a new String from the capitalized words : see String.join(separator)

提交回复
热议问题