79363728

Date: 2025-01-17 05:41:04
Score: 2
Natty:
Report link
String s = "ABCÃࠁ";
byte[] bytes = s.getBytes();
char[] charArray = s.toCharArray();

The above in debug with the default Charset of UTF-8 enter image description here

In the above, the last character in the string, which is the last element in the charArray, is "represented" by 3 bytes. Can we still say a "char" is 2 bytes? Since an array is a contiguous sequence of bytes in memory with equal number of bytes for each element, how many bytes-long might be each element of the charArray ?

Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Madhu