This post will discuss how to get the character corresponding to the given digit between 0 and 9 in Java.

1. Using Character.forDigit() method

The standard solution to get the character representation of a specific digit is to use Character.forDigit() method. It returns the char value represented by the integer in the specified radix. For example:

Download  Run Code

2. Using Casting

Another alternative is casting, which is explicitly converting one type to another. We can get the corresponding character representation of the specified digit by adding ‘0’ to it and then casting the result to a char. For example:

Download  Run Code

3. Using String.valueOf() method

Finally, we can call String.valueOf(int) method to get the string representation of the given digit and then extract the character present at the first index with String.charAt(index) method. For example:

Download  Run Code

That’s all about getting the character representation of a specific digit in Java.