在Android的/ Java字符串替换()什么都不做字符串、什么都不、Android、Java

2023-09-06 09:56:01 作者:春风忘了矜持

在安卓/ java中,我试图用 + 替换某些字符串的空间,但它似乎并没有工作。我是不是做错了?

 串串=Hello World的;
与string.replace(,+);
 

解决方案

字符串对象是不可变的,所以替换方法不会改变字符串,但创建一个新的,你必须重新保存:

 串串=Hello World的;
串与string.replace =(,+);
 
90 的同学都没搞清楚的 Java 字符串常量池问题 图文并茂

In android/java, I'm trying to replace the space in some strings with a +, but it doesn't seem to work. Am I doing it wrong?

String string="Hello world";
string.replace(" ", "+");

解决方案

String objects are immutable, so the replace method doesn't change the string but creates a new one that you have to re-save:

String string="Hello world";
string = string.replace(" ", "+");

 
精彩推荐
图片推荐