Convert String into Title Case

前端 未结 9 1296
终归单人心
终归单人心 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 15:50

    Using Java 8 streams:

    String titleCase = (new ArrayList<>(Arrays.asList(inputString.toLowerCase().split(" "))))
                       .stream()
                       .map(word -> Character.toTitleCase(word.charAt(0)) + word.substring(1))
                       .collect(Collectors.joining(" "));
    

提交回复
热议问题