Actually, the essence in question. For example, there is a string

String old = "геннадий"; 

You need to get the string Gennady, that is, the first character must go up in the register

    2 answers 2

    Option number 1:

     String capitalized = old.substring(0, 1).toUpperCase() + old.substring(1).toLowerCase(); 

    Option number 2:

     String capitalized = Character.toUpperCase(old.charAt(0)) + old.substring(1).toLowerCase(); 

    Option number 3:

     StringBuilder sb = new StringBuilder(old.toLowerCase()); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); String capitalized = sb.toString(); 
    • Great solution :) - Flippy

    Option 4:

    Use Apache Commons Lang

      String capitalized = WordUtils.capitalize (old); 

    to capitalize the whole offer, or

      String capitalized = StringUtils.capitalize (old); 

    to capitalize a single word.

    • What for? These libraries make programming easy, yes. But for such a purpose? I do not see smvsla - Flippy
    • 1. If you connect Commons Lang to your project, you will surely find many more places where you can use the classes from this library in your code. 2. This is just one more option - Igor Kudryashov
    • one
      I forgot to mention that Commons Lang correctly processes null and empty lines, and when using options 1-3, you will have to control it yourself. - Igor Kudryashov