我正在讀取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 ...「在哪裏。當你打印該數組的元素時,你只是誤解了正在發生的事情。 –