java - Create New Strings in normal memory and in string pool -
this question has answer here:
if example:
string str1 = “abc”; string str2 = new string(“def”);
then,
case 1: string str3 = str1.concat(str2)
go in heap or pool?
case 2: string str4 = str2.concat(“hi”)
go in heap or pool?
in java, whichever string u create using new keyword created in heap memory. if create string without using new, created in string pool , called string constant. there 1 copy of string constant pool value means duplicates wont there in string pool.
Comments
Post a Comment