Character Flashcards
Character Class
- The Character class wraps a value of the primitive type char in an object. An object of type Character contains a single field whose type is char.
- In addition, this class provides several methods for determining a character’s category (lowercase letter, digit, etc.) and for converting characters from uppercase to lowercase and vice versa.
compare(char x, char y) and compareTo(..)
- Compares two char values numerically. The value returned is identical to what would be returned by:
Character.valueOf(x).compareTo(Character.valueOf(y))
- compareTo(Character anotherCharacter)
Compares two Character objects numerically.
equals()
- // assign values to c1, c2
Character c1 = new Character(‘Z’);
Character c2 = new Character(‘Z’);
// assign the result of equals method on c1, c2 to res
boolean res = c1.equals(c2);
valueOf(char c)
- Character valueOf(char c)
Returns a Character instance representing the specified char value
charValue()
- charValue() is a built-in method in Java that returns the value of this character object. This method converts the Character object into its primitive data type char.
isLetterOrDigit(char ch)
- boolean isLetterOrDigit(char ch)
The function accepts a single mandatory parameter ch which signifies the character to be tested.
- Return value: This function returns a boolean value. The boolean value is true if the character is a letter or digit else it false.
isDigit(char ch)
- Determines if the specified character is a digit.
A character is a digit if its general category type, provided by Character.getType(ch), is DECIMAL_DIGIT_NUMBER.
*
isLetter(char ch)
- Returns :returns true if ch is a alphabet, otherwise return false
digit(char ch, int radix)
- The function accepts two parameters which are described below:
ch- This is a mandatory parameter which specifies the character to be converted.
radix- This is a mandatory parameter which specifies radix. This is 10 for decimal numbers.
forDigit(int digit, int radix)
- Determines the character representation for a specific digit in the specified radix. If the value of radix is not a valid radix, or the value of digit is not a valid digit in the specified radix, the null character (‘\u0000’) is returned. Radix is 10 for decimal system.
isSpaceChar()
- boolean isSpaceChar(char ch)
The function accepts one mandatory parameter ch which specifies the character to be tested.
Return Value: This method returns a boolean value. The value is True if the character is a space character, False otherwise.
getNumericValue(char ch)
- Returns the int value that the specified Unicode character represents. For example, the character ‘\u216C’ (the roman numeral fifty) will return an int with a value of 50
isWhitespace(char ch)
- Determines if the specified character is white space according to Java
isLowerCase(char ch) && isUpperCase(char ch)
- what it says
toUpperCase/toLowerCase
- returns the uppercase/lowercase form of the specified char value.