1. 计算机是如何识别什么时候该把两个字节转换为一个中文呢?
在计算机中中文的存储分两个字节:
• 第一个字节肯定是负数。
• 第二个字节常见的是负数,可能有正数。但是没影响。
2. 代码示例:
1 package com.himi.StringToArrays; 2 3 import java.util.Arrays; 4 5 public class StringDemo { 6 7 public static void main(String[] args) { 8 String s1 = "abcde"; 9 byte[] bys1 =s1.getBytes(); 10 System.out.println(Arrays.toString(bys1)); 11 12 System.out.println("-------------------"); 13 14 String s2 = "我爱你中国"; 15 byte[] bys2 = s2 .getBytes(); 16 System.out.println(Arrays.toString(bys2)); 17 18 } 19 20 }
运行效果,如下: