What is the correct way to create and display a Unicode symbol in Java when you only have the Unicode number at runtime?

I know that using String symbol = "\u2202"; correctly displays the Unicode character “∂”, but this only works when hardcoding.

Now I need to generate Java Unicode characters dynamically based on a number like 2202.

When I try String symbol = "\\u" + c;, it just gives me the literal string "\\u2202" instead of the actual character.

What’s the proper way to construct a Unicode symbol from its number during runtime?

If your Unicode number is within the Basic Multilingual Plane (i.e., up to 0xFFFF), this is the most straightforward way.

int codePoint = 2202;
char symbol = (char) codePoint;
System.out.println(symbol);  // Output: ∂

You’re directly converting the Unicode number to a character, and Java prints it as expected.

If you want the result in a String instead of a char, just wrap it like this:

int codePoint = 2202;
String symbol = String.valueOf((char) codePoint);
System.out.println(symbol);  // Output: ∂

This is useful when you’re building strings dynamically or appending the symbol elsewhere.