int to char java

‮tth‬ps://www.lautturi.com
int to char java

In Java, you can convert an int value to a char using the charValue() method of the Character class or by using a type cast.

Here is an example of how to convert an int to a char using the charValue() method:

int number = 65;
char c = Character.valueOf((char) number).charValue();  // c is 'A'

In this example, the int value is first cast to a char, and then the charValue() method is used to retrieve the char value.

You can also use a type cast to convert an int to a char directly:

int number = 65;
char c = (char) number;  // c is 'A'

The type cast operator (char) converts the int value to a char by discarding the higher-order bits and keeping the lower 16 bits. This can cause the value to be truncated, depending on the value of the int.

For more information on converting data types in Java, you can refer to the Java documentation.

Created Time:2017-11-01 22:29:53  Author:lautturi