String类的equals和==

来源:互联网 发布:数据挖掘产品 编辑:程序博客网 时间:2024/05/20 20:43

String a="abc"

String b="abc"

String c="ab"+"c"

a==b  返回true

a==c  返回true

字符串在内存池里值相同则地址相同。

 

String str1=new String("abc");

 String str2=new String("abc");

脱离了内存池,出现了new 即创建新的对象,这里是两个对象对应两个地址,古 str1==str2返回false。

 

 

 

 

0 0
原创粉丝点击