I have a question about this code:
String st = "AaHello";
byte[] bt = st.getBytes("UTF-8");
for (int i = 0; i < bt.length; i++){
System.out.println(bt[i]);
}
I don't quite understand why I got the following output: 65 97 72 101 108 108 111
I think 65 is the ASCII CODE for A, 97 is the ASCII CODE for a, 72 is the ASCII CODE for H... so it seems that it is printing out ASCII code.
But shouldn't it print the byte in the UTF-8 encoding format? (hexa decimal or binary) for example shouldn't A be printed out as 41? and then a be printed out as 61? ....
Why is it that it is not printout out the UTF-8 bytes code?
On the other hand, from the example on the JAVA oracle tutorial site, the corresponding UTF-8 actually got printed out https://docs.oracle.com/javase/tutorial/i18n/text/string.html for example here in the example: utf8Bytes[0] = 0x41
I am just wondering is my code and the code in the example doing the same thing? (I used getBytes() method too just like in the example there, why is it that I am not printing out the byte code it seems, but the example in the java oracle site is printing out the byte code correctly)?