And when I debug this, the logic gets into the sentence. replace.
Yes, and then you discard the return value.
Strings in Java are immutable - when you replace it does not change the contents of an existing row - it returns a new row with the changes. So you want:
sentence = sentence.replace("and", " ");
This applies to all methods in String ( substring , toLowerCase , etc.). None of them change the contents of the string.
Note that you really do not need to do this in the state - after all, if the sentence does not contain "and" , this does not harm the replacement:
String sentence = "Define, Measure, Analyze, Design and Verify"; sentence = sentence.replace("and", " ");
Jon Skeet 04 Oct 2018-12-12T00: 00Z
source share