I am a little bit confused at the moment. I tried that:
String test = "KP 175.105";
test.replace("KP", "");
System.out.println(test);
and got:
KP 175.105
However, I want:
175.105
What's wrong with my code?
I am a little bit confused at the moment. I tried that:
String test = "KP 175.105";
test.replace("KP", "");
System.out.println(test);
and got:
KP 175.105
However, I want:
175.105
What's wrong with my code?
You did not assign it to test
. Strings are immutable.
test = test.replace("KP", "");
You need to assign it back to test
.
Strings
are immutable so you need to assign your test
reference to the result of String.replace
:
test = test.replace("KP", "");
String is immutable in java so you have to do
test =test.replace("KP", "");