Make String first letter capital in java

后端 未结 8 2083
耶瑟儿~
耶瑟儿~ 2020-12-29 04:04

As of now I\'m using this code to make my first letter in a string capital

String output = input.substring(0, 1).toUpperCase() + input.substring(1);
<         


        
8条回答
  •  囚心锁ツ
    2020-12-29 04:37

    You should have a look at StringUtils class from Apache Commons Lang lib - it has method .capitalize()

    Description from the lib:

    Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char). No other letters are changed.

提交回复
热议问题