Make String first letter capital in java

后端 未结 8 2157
耶瑟儿~
耶瑟儿~ 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:41

    How about this:

    String output = Character.toUpperCase(input.charAt(0)) + input.substring(1);
    

    I can't think of anything cleaner without using external libraries, but this is definitely better than what you currently have.

提交回复
热议问题