Capitalizes the first letter of the given string - Java java.lang

Java examples for java.lang:String Capitalize

Description

Capitalizes the first letter of the given string

Demo Code


public class Main{

    public static void main(String[] argv){
        String text = "java2s.com";
        System.out.println(capitalize(text));
    }// w ww  . ja  va  2 s  .c o m
    /**
     * Capitalizes the first letter of the given string.
     * 
     * @param text the string to capitalize.
     * 
     * @return the modified string.
     */
    public static String capitalize(String text) {
        String h = text.substring(0, 1).toUpperCase();
        String t = text.substring(1);
        return h + t;
    }

}

Related Tutorials