关于String的两种赋值方式

String的两种赋值是不同的,String str1=“hello”,指向堆内存中的"hello",而String str2=new String("hello"),因为new开辟的新的堆内存,所以二者地址不同,在用==时,显示的是false。 例一: String str1=“Hello”; String str2=“Hello”;
相关文章
相关标签/搜索