Character.charValue() in Java with examples
Java.lang.Character.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.
Syntax:
public char charValue()
The function does not accepts any parameter.
Return Type: This method returns the primitive char value represented by this object.
Below programs illustrate the Java.lang.Character.charValue() method:
Program 1:
import java.lang.*;
public class Gfg1 {
public static void main(String[] args)
{
Character x = new Character( 'z' );
char ch = x.charValue();
System.out.println( "Primitive char value is " + ch);
}
}
|
Output:
Primitive char value is z
Program 2: When we assign the value of x by any digit:
import java.lang.*;
public class Gfg {
public static void main(String[] args)
{
Character x = new Character( '9' );
char ch = x.charValue();
System.out.println( "Primitive char value is " + ch);
}
}
|
Output:
Primitive char value is 9
Last Updated :
06 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...