Character Flashcards

1
Q

Character Class

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

compare(char x, char y) and compareTo(..)

A
  • 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

equals()

A
  • // 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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

valueOf(char c)

A
  • Character valueOf(char c)

Returns a Character instance representing the specified char value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

charValue()

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

isLetterOrDigit(char ch)

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

isDigit(char ch)

A
  • 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.

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

isLetter(char ch)

A
  • Returns :returns true if ch is a alphabet, otherwise return false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

digit(char ch, int radix)

A
  • 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

forDigit(int digit, int radix)

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

isSpaceChar()

A
  • 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

getNumericValue(char ch)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

isWhitespace(char ch)

A
  • Determines if the specified character is white space according to Java
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

isLowerCase(char ch) && isUpperCase(char ch)

A
  • what it says
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

toUpperCase/toLowerCase

A
  • returns the uppercase/lowercase form of the specified char value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

String vs Character Array

A
  • String refers to a sequence of characters represented as a single data type. Character Array is a sequential collection of data type char.
  • Strings are immutable. Character Arrays are mutable.
  • Built in functions like substring(), charAt() etc can be used on Strings. No built in functions are provided in Java for operations on Character Arrays.
  • ‘+’ can be used to appended strings together to form a new string. ‘+’ cannot be used to append two Character Arrays.
  • The charAt() method can be used to access characters at a particular index in a String. The characters in a Character Array can be accessed normally like in any other language by using [].
  • Strings can be stored in any any manner in the memory. Elements in Character Array are stored contiguously in increasing memory locations.
  • All Strings are stored in the String Constant Pool. All Character Arrays are stored in the Heap.
  • A String can be converted into Character Array by using the toCharArray() method of String class.
    Eg: String s = “GEEKS”;
    char [] ch = s.toCharArray();
  • A Character Array can be converted into String by passing it into a String Constructor.
    Eg: char[] a = {‘G’, ‘E’, ‘E’, ‘K’, ‘S’};
    String A = new String(a);