Change the replace method call to:
str1 = str1.replace("replace", "Hi");
Since String
are immutable, you need to reassign the result back to str1
. It doesn't perform in-place replacement, rather it constructs and returns a new String object. the original String is unmodified.