String的兩種實例化方式比較(JAVA學習筆記)

字符串共享產生問題:java String str = new String("hello"); 該字符串常量並無保存在常量池中,可使用String的intern()方法進行解決code String str = new String("hello").intern(); 因此String對象的兩種實例化方式的區別:對象 (1)直接賦值,直接開闢一塊堆內存空間,而且該字符串對象能夠保存在對象池中,
相關文章
相關標籤/搜索