Convert String into Title Case

前端 未结 9 1379
终归单人心
终归单人心 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条回答
  •  Happy的楠姐
    2021-01-03 16:00

    Code Golf variation... I challenge anyone to make it any simpler than this:

    public String titleCase(String str) {
        return Arrays
                .stream(str.split(" "))
                .map(String::toLowerCase)
                .map(StringUtils::capitalize)
                .collect(Collectors.joining(" "));
    }
    

提交回复
热议问题