(这个问题可能是重复的,但我真的不明白其他答案)
您有以下代码:
String str ="football";
str.concat(" game");
System.out.println(str); // it prints football
但是使用这段代码:
String str ="football";
str = str + " game";
System.out.println(str); // it prints football game
那么有什么区别以及到底发生了什么?
最佳答案
str.concat("game");
与 str + "game";
含义相同。如果您不将结果分配回某个地方,它就会丢失。你需要做的是:
str = str.concat(" game");
关于java - 字符串连接中 string.concat 和 + 运算符的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50626972/