I need to replace multiple characters with multiple replacements in a String. I want to replace the following letters:
Z, I, K, A, Y, W, X, F, S, Q, V, G, N, O, H, J, B, P, T, R, M, E, L, C, U, D
with the corresponding:
E, T, O, A, I, N, R, S, H, L, D, F, M, C, U, G, W, Y, B, P, V, K, J, Q, Z, X
For example, 'Z' becomes 'E', 'I' becomes 'T', etc. Here's some example code:
public static void main(String[] args) {
String s = "LAMA XZRQAOZ";
// Replacing code
// Output: s = "JAVA REPLACE"
}
What is the simplest way to do this?
Note: I have tried using an array along with a for loop, but that replaces the letter more than once, so it replaces it into the wrong letter.
Note2: The String I'm actually trying to do is over 10000 characters long, so I don't know if iterating 1 character at a time will be too slow in performance.
HashMap.