java.lang.Character charValue()
Description
The charValue() java method determines returns the value of this Character object. Basically this method is just a way to convert the Character object into it’s primitive data type char.
Method Syntax
public char charValue()
Method Argument
| Data Type | Parameter | Description |
|---|---|---|
| N/A | N/A | N/A |
Method Returns
The charValue() method of Character class returns the primitive char value represented by this object.
Compatibility
Requires Java 1.0 and up
Java Character charValue() Example
Below is a simple java example on the usage of charValue() method of Character class.
package com.javatutorialhq.java.examples;
/*
* This example source code demonstrates the use of
* charValue() method of Character class.
*/
public class CharacterValueExample {
public static void main(String[] args) {
// instantiate a new Character object
Character characterObject = new Character('c');
// convert characterObject to char primitive
char charPrimitive = characterObject.charValue();
// print the result
System.out.print("Character object " + characterObject
+ " primitive value is " + charPrimitive);
}
}
Sample Output
Below is the sample output when you run the above example.
