String strOne = new String("w");
String strTwo = new String("w");
strOne和strTwo用“==”和“equals”比较我能理解。
返回结果是false和true
==比较的是堆里面对象占用栈里面的内存地址false
equals比较的是堆里面对象的值true
那下面这个呢?
String str1 = "abc", str2 = "abc";
虽然str1==str2和str1.equals(str2)的结果我知道都是true,但是为什么啊?
该怎么去理解?
String strTwo = new String("w");
strOne和strTwo用“==”和“equals”比较我能理解。
返回结果是false和true
==比较的是堆里面对象占用栈里面的内存地址false
equals比较的是堆里面对象的值true
那下面这个呢?
String str1 = "abc", str2 = "abc";
虽然str1==str2和str1.equals(str2)的结果我知道都是true,但是为什么啊?
该怎么去理解?