文章目录
byte和char的区别
byte是字节数据类型、有符号型的、占1个字节、大小范围为-128——127
char是字符数据类型、无符号型的、占2个字节(unicode码)、大小范围为0-65535
byte和char在指定编码类型的情况下,可以相互转换
String、byte[]和char[]的联系
String的构造函数
byte[]转String
String(byte[] bytes)
Constructs a new String by decoding the specified array of bytes using the platform’s default charset.
String(byte[] bytes, Charset charset)
Constructs a new String by decoding the specified array of bytes using the specified charset.
String(byte[] bytes, int offset, int length)
Constructs a new String by decoding the specified subarray of bytes using the platform’s default charset.
String(byte[] bytes, int offset, int length, Charset charset)
Constructs a new String by decoding the specified subarray of bytes using the specified charset.
String(byte[] bytes, int offset, int length, String charsetName)
Constructs a new String by decoding the specified subarray of bytes using the specified charset.
String(byte[] bytes, String charsetName)
Constructs a new String by decoding the specified array of bytes using the specified charset.
char[]转String
与byte[]不同,char[]转String不用指定编码类型
String(char[] value)
Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.
String(char[] value, int offset, int count)
Allocates a new String that contains characters from a subarray of the character array argument.
String转byte[]
需指定编码类型,默认使用平台的默认编码
byte[] getBytes()
Encodes this String into a sequence of bytes using the platform’s default charset, storing the result into a new byte array.
byte[] getBytes(Charset charset)
Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array.
byte[] getBytes