Is there a function in Java which is equivalent to php’s strtr?
string strtr ( string $str , string $from , string $to )
If given three arguments, strtr function returns a copy of string where all occurrences of each (single-byte) character in $from have been translated to the corresponding character in $to, i.e., every occurrence of $from[$n] has been replaced with $to[$n], where $n is a valid offset in both arguments.
Cannot find a direct equivalence to your
strtrin the JDK. In Apache Commons StringUtils, there is StringUtils.replaceCharsString.replace Does not really fit your case, unless you use it for each letter in your
$fromargument and replace it with the$tosubstitute. It’s pretty easy to implement your own utility function using StringBuilder and replacing it yourself, though. Which is pretty much what StringUtils.replace does.