For example, if I have Hello World
it should become Holle Werld
. How can I do this using String.replace
? I've tried doing "Hello World".replace("e","o")
but I only get Hollo World
and if I use it again I will get Helle Werld
.
You could also do:
String result = Arrays.stream(input.split(""))
.map(c -> c.equals("e") ? "o" : c.equals("o") ? "e" : c)
.collect(Collectors.joining());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With