英文:
How do I copy the entire literal text of a string in Java?
问题
我刚开始接触编程,所以这可能听起来像是一个愚蠢的问题,但是在这里:
`String yes = "Yes. ";`
`String no = "But no.";`
`String whole = yes + no;`
当你打印whole时,你会得到"Yes. But no."
`yes = "No."`
`String whole2 = whole;`
我希望whole2的值是"yes + no;",因为变量"yes"已经被编辑,我希望它显示新数据。然而,whole2只会得到"Yes. But no."。我是否有办法做到这一点?如果没有,请描述另一种可以获得我期望结果的方法。
英文:
I'm new to coding, so this may sound like a dumb question, but here:
String yes = "Yes. ";
String no = "But no.";
String whole = yes + no;
When you print whole, you get "Yes. But no."
yes = "No."
String whole2 = whole
;
I want whole2's value to be "yes + no;" because the variable "yes" has been edited and I want it to display the new data. However, whole2 only gets "Yes. But no." Is there any way I can do this? If not, please describe another way that gets the result I prefer.
答案1
得分: 0
以下是翻译好的部分:
简单的方法就是将其再次赋值给相同的变量。
例如:
String whole2 = yes + no;
这样可以避免创建冗余的方法等。
英文:
The simple way to do it is just to assign it to the same variables again.
For example:
String whole2 = yes + no;
It saves the hassle of creating redundant methods etc,.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论