“第九大类型”-字符串String
概念
字符:char类型是按照Unicode规范实现的一种数据类型,固定16bit大小,例如:‘a’,‘中’,’\u4e00’
字符串:多个字符连接起来组合成的字符序列,例如:“中国”
String的底层实现
string底层实现是一个字符数组
String的定义
String str = new String(“hello”);
String str = “hello”; {常用}
字符串常量池
以String str = new String(“hello”);创建过程为例子
1.检查字符串常量池中有"hello"字符串
2如果有hello,str引用常量池中的hello
3.如果没有hello,则在常量池中创建hello,str引用常量池中的hello