Character.toTitleCase() in Java

Character.toTitleCase(): This method is available in java.lang.Character class of Java.

Approach 1: When the argument is of type char.

Syntax:

char java.lang.Character.toTitleCase(char ch)

This method takes one argument of type char as its parameter. This method converts the character argument to titlecase using case mapping information from the UnicodeData file.

Parameters: One parameter is required for this method.

ch: the character to be converted.

Returns: the titlecase equivalent of the character, if any; otherwise, the character itself.

Exceptions: NA

Java

public class CharactertoTitleCasechar {
    public static void main(String[] args) {

        char ch = 'a';
        System.out.println(Character.toTitleCase(ch));
    }
}

Output:

A


Approach 2: When the argument is of type int.

Syntax:

int java.lang.Character.toTitleCase(int codePoint)

This method takes one argument of type int as its parameter. This method converts the character (Unicode code point) argument to titlecase using case mapping information from the UnicodeData file.

Parameters: One parameter is required for this method.

codePoint: the character (Unicode code point) to be converted.

Returns: the titlecase equivalent of the character, if any; otherwise, the character itself.

Exceptions: NA

Java

public class CharactertoTitleCaseint {
    public static void main(String[] args) {

        int codePoint = 'a';
        System.out.println(Character.toTitleCase(codePoint));
    }
}

Output:

65

No comments:

Post a Comment