Why does String.replace not work? [duplicate]

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

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

You need to assign it back to test.

Leave a Comment