關於String的兩種賦值方式

String的兩種賦值是不同的,String str1=「hello」,指向堆內存中的"hello",而String str2=new String("hello"),因爲new開闢的新的堆內存,所以二者地址不同,在用==時,顯示的是false。 例一: String str1=「Hello」; String str2=「Hello」;
相關文章
相關標籤/搜索