一、构造
- 字符串 -> 字符数组包装成的对象
char[] cs = {'h','e','l','l','o'};
System.out.println(cs);//hello
String str = "hello1";
str = "hi";
System.out.println(str);//hi
- 构造器
String s1 = new String(); // ""
s1 = new String("哈哈"); // s1 = "哈哈"
System.out.println(s1.toString());//哈哈
- 构造器
s1 = new String(new char[] {'h','e','l','l','o'});// hello
二、编码问题
编码问题 JVM 字符集Unicode \u4e2d
操作系统:GBK(1个字符=2个字节) UTF-8(1个字符=3个字节)
String str = "你好";
- 字符 -> 字节:解码 str.getBytes()
byte[] bsUTF = str.getBytes()