How to capitalize the first letter of word in a string using Java?

前端 未结 25 1393
抹茶落季
抹茶落季 2020-11-27 09:50

Example strings

one thousand only
two hundred
twenty
seven

How do I change the first character of a string in capital letter and not change

25条回答
  •  渐次进展
    2020-11-27 10:37

    public String capitalizeFirstLetter(String original) {
        if (original == null || original.length() == 0) {
            return original;
        }
        return original.substring(0, 1).toUpperCase() + original.substring(1);
    }
    

    Just... a complete solution, I see it kind of just ended up combining what everyone else ended up posting =P.

提交回复
热议问题