title: Replacing individual characters in a StringBuffer
body: <p>I'm trying to replace the individual 'a' character in 'Amazon' by using the <strong>.replace</strong> method in Java.</p>
  
  <p>I know how to do this with Strings, but when I use the code below with StringBuffers, I get an output of 'Amaazon' instead. </p>
  
  <p>Does anyone know of a way to replace the individual characters in a StringBuffer?</p>
  
  <pre><code>    public class Hello {
  
      public static void main(String argv[]) {
      StringBuffer str1 = new StringBuffer("Amazon");
      String str = new String("Rainforest");
      int a = str.indexOf('o',2);
      StringBuffer str2 = str1.replace(2, 2, "a");
      System.out.println(a);
      System.out.println(str2);
      } 
  } 
  </code></pre>
  
  <p>Managed to find the right way to do it through the answer, so I thought I'd post my corrected code:</p>
  
  <pre><code>public class Hello {
  
  public static void main(String argv[]) {
  StringBuffer str1 = new StringBuffer("Amazon");
  String str = new String("Rainforest");
  int a = str.indexOf('o',2);
  StringBuffer str2 = str1.replace(0, 1, "b");
  System.out.println(a);
  System.out.println(str2);
  } 
  </code></pre>
  
  <p>} </p>
  
  <p>To get the output of "bmazon"</p>
  
  <p>Thanks to the answerer! </p>