The documentation of the String class says that replace() returns a new String:
string.replace(substring1, substring2)
Parameters:
string: a variable of type String
substring1: another variable of type String
substring2: another variable of type String
Returns: another String containing the new string with replaced characters.
However, the source code seems to indicate that the return type is void:
When it says “Returns:” it’s not really implied as if it’s a returned value from a function call. Since the String we are talking about here is a Class, it has Methods and those methods are functions… yes… but the Input is the instance of the String object string from your example, and the “Returns:” is actually saying "when your program continues past the point you executed string.replace(substring1, substring2), that string will contain the new string with replaced characters.
Well, I’d say that the documentation is incorrect, then. It would be more correct for it to say that the method returns nothing, but that the original string is modified in-place.