[HD Pg 133, Sec. 3.5.3 - garbage-collection-of-strings]
Posted: Mon Jan 14, 2019 2:55 pm
String str = "hello";
for(int i=0; i<5; i++){
str = str + i;
}
In the above example, does JVM cache the object str or str+i (similar to valueOf would) or actually creates 11 new string objects on the heap?
for(int i=0; i<5; i++){
str = str + i;
}
In the above example, does JVM cache the object str or str+i (similar to valueOf would) or actually creates 11 new string objects on the heap?