I found some tricky place and couldn't understand how does this exactly happen.
Why string which contains one character can return different byte arrays?
Code:
public class Application {
public static void main(String[] args) throws Exception {
char ch;
ch = 0x0001;
System.out.println(Arrays.toString(("" + ch).getBytes("UTF-8")));
ch = 0x0111;
System.out.println(Arrays.toString(("" + ch).getBytes("UTF-8")));
ch = 0x1111;
System.out.println(Arrays.toString(("" + ch).getBytes("UTF-8")));
}
}
Output will be next:
[1]
[-60, -111]
[-31, -124, -111]
Why exactly this happen?
