在java中使String成为首字母大写 [英] Make String first letter capital in java
本文介绍了在java中使String成为首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
截至目前,我正在使用此代码以字符串形式生成我的第一个字母
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);
这对我来说似乎很脏..有任何直接或优雅的方式......
This seems very dirty to me ..is there any direct or elegant way..
推荐答案
这个怎么样:
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.
这篇关于在java中使String成为首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文