简体   繁体   English

当我们进行 concat 操作时,字符串会在 java 中创建 object 吗?

[英]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.当第 1 行执行时,字符串将在 scp 和堆中创建对象。

What about the line 2 statement?第 2 行语句呢? In this case also it creates in scp and heap?在这种情况下,它还会在 scp 和堆中创建吗?

Thanks in advance提前致谢

"railway" and "station" will be in Constant Pool. “铁路”和“车站”将在恒池中。

str1 and str2 will be in heap. str1 和 str2 将在堆中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用+运算符concat时创建的新String对象在哪里 - Where is the new Object of String created when we concat using + operator 在构造函数中传递的String文字在哪里,当我们创建新的String对象时存储 - Where is the String literal which was passed in the constructor, stored when we create a new String object 使用Java流对concat字符串执行算术运算 - Execute arithmetic operation on concat String with Java Streams 当我们使用new运算符在java中的字符串中实例化时,在哪里创建了第三个对象 - When we instantiate in string in java using new operator where is 3rd object created 当我们在字符串上调用toString时,它会创建一个新对象吗? - Does toString create a new object when we call it on a String? 我们如何在java中每行的结尾处连接一个String? - How can we concat a String at the end of each line in java? 当我们有 Class 类型的 object 时,如何在 Java 中创建实例 - How to create a instance in Java when we have object of type Class 何时在 Java 中使用 String#concat() 方法? - When to use String#concat() method in Java? 在Java中,当我们使用函数'FileReader(String fileName)'时,应该在哪里保存文件fileName? - In java when we use the function 'FileReader(String fileName)', where should we keep the file fileName? 对string和null关键字进行Concat操作 - Concat operation on string and null keyword
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM