Convert int to char in java
To convert an int
value to a char
value in Java, you can use the char
type's conversion method, (char)
. This method takes an int
value as an argument and returns the corresponding char
value.
Here's an example of how you can use the (char)
method to convert an int
value to a char
value:
int intValue = 65;
char charValue = (char) intValue;
System.out.println(charValue); // Outputs 'A'
In this example, the int
value 65
is passed as an argument to the (char)
method. The method returns the corresponding char
value, which is 'A'
. The char
value is then printed to the console.
Note that the (char)
method only works for int
values that represent valid Unicode characters. If you pass an int
value that is outside the range of valid Unicode characters (0 to 65535), the method will return an undefined character.