Of course! Converting an int to a char in Java is a common task. The most important thing to understand is that you're not converting the integer value (like 65) to its string representation ("65"), but rather converting the integer to its corresponding Unicode character.

Here’s a detailed breakdown of the methods, from the most common to more specialized cases.
The Core Concept: char is a Numeric Type
In Java, char is a 16-bit unsigned numeric type, just like short and byte. It uses the UTF-16 encoding to represent characters. This means you can perform arithmetic on char variables and treat them as numbers.
'A'has an integer value of65.'B'has an integer value of66.'a'has an integer value of97.'0'has an integer value of48.
This fundamental understanding is key to the conversion.
Method 1: Simple Casting (Most Common)
This is the direct and most efficient way to convert an int to a char. It simply takes the lowest 16 bits of the int and uses them as the value for the char.

Syntax
char myChar = (char) myInt;
Example
public class IntToCharExample {
public static void main(String[] args) {
int number = 65;
// Cast the int to a char
char letter = (char) number;
System.out.println("The integer is: " + number); // Output: The integer is: 65
System.out.println("The char is: " + letter); // Output: The char is: A
}
}
When to Use It
- When you have an integer that you know represents a valid Unicode code point (e.g., from
65to65535). - When you are working with ASCII values and want to get the corresponding character.
- This is the standard, go-to method for this conversion.
Method 2: Using Character.forDigit()
This method is specifically designed to convert an integer digit (0-9) into its corresponding character ('0'-'9'). It's useful when you want to ensure the integer is actually a digit.
Syntax
char digitChar = Character.forDigit(int digit, int radix);
digit: The integer to convert (must be between 0 andradix - 1).radix: The base of the number system (e.g.,10for decimal,16for hexadecimal).
Example
public class ForDigitExample {
public static void main(String[] args) {
int decimalDigit = 7;
int hexDigit = 11; // Represents 'B' in hex
// Convert a decimal digit
char charFromDecimal = Character.forDigit(decimalDigit, 10);
System.out.println("Digit " + decimalDigit + " is char: " + charFromDecimal); // Output: Digit 7 is char: 7
// Convert a hexadecimal digit
char charFromHex = Character.forDigit(hexDigit, 16);
System.out.println("Hex digit " + hexDigit + " is char: " + charFromHex); // Output: Hex digit 11 is char: b
}
}
When to Use It
- When you are converting an integer that you know is a single digit (0-9) and you want the character
'0'-'9'. - When working with numbers in different bases (like binary, octal, hex) and need their digit characters.
Method 3: Using String.valueOf()
This method converts the int to its String representation first, and then gets the first character of that string. This is not the same as casting. It converts the number 65 to the string "65" and then takes the character '6'.
Syntax
char firstCharOfString = String.valueOf(myInt).charAt(0);
Example
public class StringValueOfExample {
public static void main(String[] args) {
int number = 65;
// This converts "65" to '6', NOT 'A'
char incorrectChar = String.valueOf(number).charAt(0);
System.out.println("The int is: " + number);
System.out.println("The char from String.valueOf is: " + incorrectChar); // Output: The char from String.valueOf is: 6
}
}
When to Use It
- Almost never for converting a number to its character equivalent.
- Use it only if your specific goal is to get the first character of the integer's string representation (e.g., getting
'6'from65).
Method 4: Using Integer.toString().charAt(0)
This is functionally identical to Method 3. It's just another way to achieve the same (and usually incorrect for this purpose) result.
Syntax
char firstCharOfString = Integer.toString(myInt).charAt(0);
Example
public class ToStringExample {
public static void main(String[] args) {
int number = 10;
// This converts "10" to '1'
char incorrectChar = Integer.toString(number).charAt(0);
System.out.println("The int is: " + number);
System.out.println("The char from Integer.toString is: " + incorrectChar); // Output: The char from Integer.toString is: 1
}
}
Important Considerations
Handling Numbers Outside the char Range
A char can only hold values from 0 to 65535. If you try to cast an int outside this range, Java will truncate the higher bits to fit it into a 16-bit char. This can lead to unexpected results.

public class OutOfRangeExample {
public static void main(String[] args) {
int largeNumber = 70000; // This is outside the char range (0-65535)
// Java truncates 70000 to fit into a 16-bit char
// 70000 in binary is ... 0001 0000 0100 0011 1000 0000
// Taking only the last 16 bits gives 0100 0011 1000 0000
// Which is decimal 17280, corresponding to the character 䨀
char myChar = (char) largeNumber;
System.out.println("The int is: " + largeNumber);
System.out.println("The resulting char is: " + myChar); // Output: The resulting char is: 䨀
}
}
If you need to handle code points beyond the Basic Multilingual Plane (BMP), you should use the int to String conversion with Character.toChars().
Negative Numbers
Casting a negative int to a char will result in a character. Java doesn't throw an error; it just interprets the 2's complement representation of the negative number as an unsigned 16-bit value.
public class NegativeExample {
public static void main(String[] args) {
int negativeNumber = -1;
// The two's complement representation of -1 in 16 bits is all 1s (65535 unsigned)
// The character for code point 65535 is a special "non-character".
char myChar = (char) negativeNumber;
System.out.println("The int is: " + negativeNumber);
System.out.println("The resulting char is: " + myChar); // Output: The resulting char is: � (often a replacement character)
}
}
Summary Table
| Method | What it Does | Best For | Example |
|---|---|---|---|
(char) myInt |
Takes the lowest 16 bits of myInt as the character's Unicode value. |
Converting an integer to its corresponding character. (e.g., 65 -> 'A') |
char c = (char) 65; |
Character.forDigit(d, 10) |
Converts an integer digit d (0-9) to its character representation ('0'-'9'). |
Converting numbers to their digit characters, especially in different bases. | char c = Character.forDigit(7, 10); |
String.valueOf(myInt).charAt(0) |
Converts myInt to a string (e.g., 65 -> "65") and gets the first char. |
Getting the first character of the integer's string representation. | char c = String.valueOf(65).charAt(0); |
