关于Integer.toString(char)返回值:返回1087时char变量c的可能取值是什么?
c when Integer.toString(c) returns "1087"? Great question! Let's break this down step by step:
First, let's clarify the method behavior in Java: there’s no direct Integer.toString(char) overload. When you pass a char variable to Integer.toString(), the char is automatically promoted to an int—since char is essentially a 16-bit unsigned integer representing a UTF-16 code unit. This means we’re actually calling the Integer.toString(int i) method, which converts the integer value to its decimal string form.
If the return value is "1087", that tells us the promoted int value is exactly 1087. Reversing this logic, c must be the char corresponding to the integer 1087.
To get this char, you’d cast the integer back to the char type:
char c = (char) 1087;
In Unicode terms, this is the character U+043F—the Cyrillic small letter "п" (pronounced similarly to the English "p").
You can verify this with a quick code snippet:
char c = (char) 1087; System.out.println(Integer.toString(c)); // Outputs "1087"
A quick sanity check: since char in Java has a valid range of 0 to 65535 (as an unsigned 16-bit type), 1087 is well within bounds, so this is a fully valid char value.
内容的提问来源于stack exchange,提问作者user8208522

