THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
while digit('a',10) returns 1.

public static intgetNumericValue(codePointch)

Returns the numeric value of the digit ch. For example, the character
\u217F is the Roman numeral digit M, so
getNumericValue('\u217F') returns the value 1000. These numeric
values are non-negative. If ch has no numeric value, 1 is returned; if it has a
value but is not a non-negative integer, such as the fractional value ¼
('\u00bc'), getNumericValue returns 2.

public static charforDigit(int digit, int radix)

Returns the character value for the specified digit in the specified radix. If the
digit is not valid in the radix, the character '\u0000' is returned. For
example, forDigit(10,16) returns 'a' while forDigit(16,16)
returns '\u0000'.

There are three character cases in Unicode: upper, lower, and title. Uppercase and lowercase are familiar to
most people. Titlecase distinguishes characters that are made up of multiple components and are written
differently when used in titles, where the first letter in a word is traditionally capitalized. For example, in the
string "ljepotica",[2] the first letter is the lowercase letter lj(\u01C9 , a letter in the Extended Latin
character set that is used in writing Croatian digraphs). If the word appeared in a book title, and you wanted
the first letter of each word to be in uppercase, the correct process would be to use toTitleCase on the
first letter of each word, giving you "Ljepotica" (using Lj, which is \u01C8). If you incorrectly used
toUpperCase, you would get the erroneous string "LJepotica" (using LJ, which is \u01C7).


[2] "Ljepotica" is a Croatian diminutive of "beauty," often used as a term of endearment and
admiration.

All case issues are handled as defined in Unicode. For example, in Georgian, uppercase letters are considered
archaic, and translation into uppercase is usually avoided. Therefore, toUpperCase will not change
lowercase Georgian letters to their uppercase equivalents, although toLowerCase will translate uppercase
Georgian letters to lowercase. Because of such complexities, you cannot assume that converting characters to
either lower or upper case and then comparing the results will give you a proper case-ignoring comparison.
However, the expression


Character.toUpperCase(Character.toLowerCase(ch));

leaves you with a character that you can compare with another similarly constructed character to test for
equality ignoring case distinctions. If the two resulting characters are the same, then the original characters
were the same except for possible differences in case. The case conversion methods are:


public staticcodePointtoLowerCase(codePointch)

Returns the lowercase character equivalent of ch. If there is no lowercase
equivalent, ch is returned.

public staticcodePointtoUpperCase(codePointch)

Returns the uppercase character equivalent of ch. If there is no uppercase
equivalent, ch is returned.

public staticcodePointtoTitleCase(codePointch)
Free download pdf