我正在读取getbytes并从文档中指出它将返回 结果字节数组。String.getBytes()返回Unicode字符数组
但是当我运行下面的程序时,我发现它是返回Unicode符号数组。
public class GetBytesExample {
public static void main(String args[]) {
String str = new String("A");
byte[] array1 = str.getBytes();
System.out.print("Default Charset encoding:");
for (byte b : array1) {
System.out.print(b);
}
}
}
上述程序打印输出
Default Charset encoding:65
这65
相当于A
Unicode表示。我的问题是,哪里是预期返回类型的字节。
你期望这种方法返回什么?你只是打印返回数组的每个字节,所以他们肯定在那里。你的期望是什么? –
*“我的问题返回类型的字节在哪里。”*在变量'b'中?很不清楚你的代码问题是什么。 – Tom
“数组中的字节”Well ...“在哪里。当你打印该数组的元素时,你只是误解了正在发生的事情。 –