Java - How to capitalize the first letter of a String
In this section, we will show you how to capitalize the first letter of a String. In Java, we can use str.substring( 0 , 1 ).toUpperCase() + str.substring( 1 ) to make the first letter of a String as a capital letter (uppercase letter) String str = "java" ; String cap = str .substring( 0 , 1 ).toUpperCase() + str .substring( 1 ); //cap = "Java" or We can use Apache's common library StringUtils.capitalize(str) API to capitalize first letter of the String. String str = "java" ; String cap = StringUtils . capitalize ( str ); //cap == "Java" 1. str.substring(0,1).toUpperCase() + str.substring(1) A complete Java example to capitalize the first letter of a String. public class Main { public static void main ( String [] args) { System . out .println( capitalize ( "knowledgefactory" )); // Knowledgefactory System . out .println( capitalize ( "java" )); // Java } // with some null an