如何在Java中复制字符串的整个字面文本?

huangapple go评论67阅读模式
英文:

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,.

huangapple
  • 本文由 发表于 2020年9月18日 09:38:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63948206.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定