How to capitalize the first character of each word in a string

后端 未结 30 1805
情深已故
情深已故 2020-11-22 02:08

Is there a function built into Java that capitalizes the first character of each word in a String, and does not affect the others?

Examples:

  • jon
30条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 02:31

    With this simple code:

    String example="hello";
    
    example=example.substring(0,1).toUpperCase()+example.substring(1, example.length());
    
    System.out.println(example);
    

    Result: Hello

提交回复
热议问题