The fact that the replace method returns a string object rather than replacing the contents of a given string is a little obtuse (but understandable when you know that strin
When you're replacing single characters, consider iterating over your character array but replace characters by using a (pre-created) HashMap
.
I use this strategy to convert an integer exponent string by unicode superscript characters.
It's about twice as fast compared to String.replace(char, char)
. Note that the time associated to creating the hash map isn't included in this comparison.