gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:16:00 25 4
gpt4 key购买 nike

<分区>

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

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 no then what will be the result of str1.intern();?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com