title: How to replace two characters in a String with replace/regex?
body: <p>I want to modify two characters in the string, for example change each <code>'i'</code> into <code>'e'</code>, and each <code>'e'</code> into <code>'i'</code> so text like <code>"This is a test"</code> will become <code>"Thes es a tist"</code>. </p>
  
  <p>I've made a solution that works, but it is boring and inelegant:</p>
  
  <pre><code>String input = "This is a test";
  char a = 'i';
  char b = 'e';
  
  char[] chars = input.toCharArray();
  for(int i = 0; i &lt; chars.length; i++) {
      if(chars[i] == a) {
          chars[i] = b;
      }else if(chars[i] == b) {
          chars[i] = a;
      }
  }
  
  input = new String(chars);
  </code></pre>
  
  <p>How can this be accomplished with regex?</p>