String类是JAVA中一个非常重要的类,继承自charSequence类,是一组不可变的Character队列。String内部以hashcode与UNICODE来储存内部的数据,所以在这个字符集外的,都占两个字节。由于String的不可变特性。对于String的任何改变,本质上都是新建了一个String对象。
String类的初始化
String类支持四种常用初始化方式,也有其他初始化方式。
//默认初始化
public String() {
this.value = "".value;
this.coder = "".coder;
}
//使用char数组初始化
public String(char value[]) {
this(value, 0, value.length, null);
}
//使用String变量
public String(String original) {
this.value = original.value;
this.coder = original.coder;
this.hash = original.hash;
}
//截取数组的一部分进行初始化,下面的数组也可以使用byte类型
public String(char value[], int offset, int count) {
public String(int[] codePoints, int offset, int count) {
checkBoundsOffCount(offset, count, codePoints.length);
if (count == 0) {