Java中Char和Byte的区别
char和byte的区别
-
char无符号数,占2个字节。0~65535
-
byte有符号数,占1个字节。-128~127
System.out.println(Byte.MAX_VALUE); //-128 System.out.println(Byte.MIN_VALUE); //127
-
java用char表示一个字符
char a='a';
char b='中';
-
char可以表示中文字符,byte不可以。(一个字占2个字节)
-
char、byte、int对于英文字符,可以相互转化
char a = 'a'; int b = a; System.out.println(b); //97 byte c = (byte) b; System.out.println(c); //97