package demo;
public class String_02 {
/*
String对象的特点
1)通过new创建字符串对象,每一次new都会申请一个新的内存空间,虽然内容相同,但是地址值不同
char[] chs = {'a','b','c'};
String s1 = new String(chs);
String s2 = new String(chs);
2)以""方式给出的字符串,只要字符序列相同(顺序和大小写),无论程序代码出现几次,
JVM都只会建立一个String对像,并在字符串池中维护
*本质上是同一个对象(地址相同)
*/
public static void main(String[] args) {
char[] chs = {'a', 'b', 'c'};
String s1 = new String(chs);
String s2 = new String(chs);
System.out.println(s1==s2);
String s3 = "abc";
String s4 = "abc";
System.out.println(s1==s3);
System.out.println(s3==s4);
}
}
String_02
最新推荐文章于 2022-04-28 11:32:40 发布