Mark
12/04/2020, 7:35 AMString.replace(String, String)
for an unlikely replacement, does it ever makes sense to wrap in a CharSequence.contains(CharSequence)
call, for efficiency?Vampire
12/04/2020, 9:15 AMMark
12/04/2020, 10:30 AM"hello".replace("x", "y")
returns the same "hello"
instance whereas "hello".replace("e", "e")
returns a different one.Vampire
12/04/2020, 10:39 AMVampire
12/04/2020, 10:41 AMOut of interest,I'd say the first one is a slight bug that is totally pointless. The docs say "Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string with the specified [newValue] string.". But as `String`s are immutable anyway it doesn't make sense to create a new instance for the first case. To have the latter return the same instance it would need an additional check whether both parameters are the same which is useless in 99% of the cases.returns the same"hello".replace("x", "y")
instance whereas"hello"
returns a different one."hello".replace("e", "e")
Mark
12/04/2020, 10:45 AMVampire
12/04/2020, 10:47 AMMark
12/04/2020, 10:48 AMVampire
12/04/2020, 10:51 AMMark
12/04/2020, 10:52 AM