String

来源:互联网 发布:淘宝提醒发货不见了 编辑:程序博客网 时间:2024/06/08 03:16

String类创建一个对象后是不可变的,就是说每设置一个值就创建一个对象;但是

String a ="hello";

String b= "hello";

a==b返回true 多次重复的常量,java 编译的程序只创建一个


String c = new String("hello");

String d = new String("hello");

a==c返回false 

c==d返回false因为不同对象;


a=a+"wolrd";

字符串a被改变指向新的内存地址;

0 0
原创粉丝点击