How to capitalize the first letter of a String in Java

In Java, we can use substring(0, 1).toUpperCase() + str.substring(1) to make the first letter of a String as a capital letter (uppercase letter)

substring(0,1).toUpperCase() + str.substring(1)

A complete Java example to capitalize the first letter of a String, and a null and length checking.

Output




References




Please don’t forget to leave a comment if you have any questions.

You may also like...

Leave a Reply

Your email address will not be published.