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:
// Java program to demonstrate the // Java.lang.Character.charValue() method // when the assigned char is a character import java.lang.*; public class Gfg1 { public static void main(String[] args) { // Create a character object Character x = new Character( 'z' ); // assign the primitive value to a character char ch = x.charValue(); System.out.println( "Primitive char value is " + ch); } } |
Primitive char value is z
Program 2: When we assign the value of x by any digit:
// Java program to demonstrate the // function when the assigned value is // a number import java.lang.*; public class Gfg { public static void main(String[] args) { // create a Character object x Character x = new Character( '9' ); // assign value is a number // assign the primitive value to a character char ch = x.charValue(); // print the primitive char value System.out.println( "Primitive char value is " + ch); } } |
Primitive char value is 9
Recommended Posts:
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.concurrent.Phaser class in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.