init cap java

www.la‮oc.iruttu‬m
init cap java

To capitalize the first letter of a string in Java, you can use the substring() and toUpperCase() methods of the String class.

Here is an example of how to capitalize the first letter of a string in Java:

public class InitCapExample {
    public static void main(String[] args) {
        String input = "hello, world!";

        // Capitalize the first letter of the string
        String output = input.substring(0, 1).toUpperCase() + input.substring(1);

        System.out.println(output);
    }
}

Output:

Hello, world!

In this example, the substring() method is used to extract the first letter of the string and the toUpperCase() method is used to convert it to uppercase. The resulting string is then concatenated with the rest of the original string using the + operator.

This technique can be used to capitalize the first letter of any string in Java. You can also use the toLowerCase() method to convert the rest of the string to lowercase, if desired.

For more information on the String class and its methods, you can refer to the Java documentation.

Created Time:2017-11-01 22:29:51  Author:lautturi