为什么 String.replace 不起作用? [英] Why does String.replace not work?

查看:21
本文介绍了为什么 String.replace 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有点困惑.我试过了:

I am a little bit confused at the moment. I tried that:

String test = "KP 175.105";
test.replace("KP", "");
System.out.println(test);

并得到:

KP 175.105

但是,我想要:

175.105

我的代码有什么问题?

推荐答案

您没有将其分配给 test.字符串是不可变的.

You did not assign it to test. Strings are immutable.

test = test.replace("KP", "");

您需要将其分配回 test.

这篇关于为什么 String.replace 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆