Displaying Titlecase Characters
After understanding code points and learning how to iterate through them, the next step is to display the titlecase characters. Titlecase, also known as initial caps or capital case, is a style of capitalization where the first letter of each word is capitalized, while the remaining letters are in lowercase.
Determining Titlecase Characters
To determine the titlecase character of a given code point, you can use the Character.toTitleCase()
method in Java. This method takes a code point as an argument and returns the titlecase character corresponding to that code point.
int codePoint = 'a';
int titlecaseCodePoint = Character.toTitleCase(codePoint);
System.out.println((char) titlecaseCodePoint); // Output: A
In the example above, the titlecase character for the code point 'a'
is 'A'
.
Iterating Through Code Points and Displaying Titlecase Characters
To iterate through code points and display their titlecase characters, you can combine the techniques you learned in the previous section. Here's an example:
String text = "LabEx 🚀";
int codePointCount = text.codePointCount(0, text.length());
for (int i = 0; i < codePointCount; i++) {
int codePoint = text.codePointAt(i);
int titlecaseCodePoint = Character.toTitleCase(codePoint);
System.out.println("Code Point: " + codePoint + ", Titlecase: " + (char) titlecaseCodePoint);
}
This code will output:
Code Point: 76, Titlecase: L
Code Point: 97, Titlecase: A
Code Point: 98, Titlecase: B
Code Point: 69, Titlecase: E
Code Point: 120, Titlecase: X
Code Point: 32, Titlecase:
Code Point: 128640, Titlecase: 🚀
Note that the titlecase character for the rocket emoji (🚀
) is the emoji itself, as emojis do not have a distinct titlecase representation.
By understanding code points, iterating through them, and using the Character.toTitleCase()
method, you can effectively display the titlecase characters in your Java applications.