Individual characters are represented in Java by the primitive char type. The Java
platform also defines a Character class, which defines useful class methods for checking the type of a character and for converting the case of a character
char[] text = new char[]{'j','a','v','a'}; // An array of
characters, initialized somewhere else
int p = 0; // Our current
position in the array of characters
//
Skip leading whitespace
while((p < text.length) &&
Character.isWhitespace(text[p])) p++;
//
Capitalize the first word of text
while((p < text.length) &&
Character.isLetter(text[p])) {
text[p] = Character.toUpperCase(text[p]);
p++;
}
No comments:
Post a Comment