title: String replace isn't working in for loop - Java
body: <p>For some reason this code doesn't work.</p>
  
  <pre><code>public void actionPerformed(ActionEvent e) {
  
              Random random = new Random();
              int randomChar = random.nextInt((23 - 0) + 1);
              for(int x = 23;x &gt; 0;x-- ) {
  
                  String text;
                  text = original.getText();
                  text = text.toLowerCase();
                  text = text.replace(alphabet[x], alphabet[randomChar]);
  
                  newText.setText(text);
  
              }
  </code></pre>
  
  <p>Just to clear a couple things up original and newText are JTextField, and alphabet is a char array with a-z.</p>
  
  <p>Now when I run this it should go through and replace every character with a random one, starting at Z and ending at A however it just gives me the exact same string that I entered back, just converted to lowercase.</p>
  
  <p>It's worth noting that if I replace                     </p>
  
  <pre><code>text = text.replace(alphabet[x], alphabet[randomChar]);
  </code></pre>
  
  <p>With</p>
  
  <pre><code>text = text.replace(alphabet[0], alphabet[randomChar]);
  </code></pre>
  
  <p>And put a bunch of A's into the input box it does change them into a random letter. EG:</p>
  
  <pre><code>aaaa input
  llll output
  or gggg output
  </code></pre>
  
  <p>it just doesn't work if I have a variable in there.</p>
  
  <p>The rest of the code isn't important by the way, it's all declaring variables and setting up the GUI.</p>
  
  <p>Any help is much appreciated!</p>