小编Yog*_*gam的帖子

字符串池可以包含两个具有相同值的字符串吗?

字符串池可以包含两个具有相同值的字符串吗?

String str = "abc";
String str1 = new String("abc");

   Will the second statement with `new()` operator creates two objects of `string` "abc", one on `heap` and another on `string` pool? 

   Now if i call intern() on str1 ie str1.intern(); as a third statement, will str1 refer to the "abc" from String pool? 

  If yes then what will happen to the object that was created on heap earlier by the new(). Will that object be eligible for garbage collection.?
  If …
Run Code Online (Sandbox Code Playgroud)

java string

1
推荐指数
1
解决办法
1763
查看次数

标签 统计

java ×1

string ×1