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

查看:375
本文介绍了为什么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.Strings是 immutable

you did not assigned to test.Strings are immutable

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

您需要再次分配给测试。

you need to assign to test again.

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

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