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

前端 未结 25 1381
抹茶落季
抹茶落季 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:51

    Update July 2019

    Currently, the most up-to-date library function for doing this is contained in org.apache.commons.lang3.StringUtils

    import org.apache.commons.lang3.StringUtils;
    
    StringUtils.capitalize(myString);
    

    If you're using Maven, import the dependency in your pom.xml:

    
      org.apache.commons
      commons-lang3
      3.9
    
    

提交回复
热议问题