简体   繁体   中英

Where string will create object in java when we did concat operation?

I wrote the following;

String str1 = new String("railway"); // line 1
String str2 = str1.concat("station"); // line 2

When line 1 executes string will create objects in scp and heap.

What about the line 2 statement? In this case also it creates in scp and heap?

Thanks in advance

"railway" and "station" will be in Constant Pool.

str1 and str2 will be in heap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM