title: Different Between StringBuffer and String
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2439243/what-is-the-difference-between-string-and-stringbuffer-in-java">what is the difference between String and StringBuffer in java?</a>  </p>
  </blockquote>
  
  
  
  <p>When I test a function using StringBuffer and String. When I use StringBuffer, I get the java.lang.OutOfMemoryError within the 2 or 3 secound.But, when I use String, I did not get java.lang.OutOfMemoryError error until one minutes. What different them, I don't know exactly.</p>
  
  <pre><code>public void print() {
      StringBuffer buffer = new StringBuffer();
      double result = 1.0 / 7.0;
      buffer.append(result);
      while (result != 0) {
          result = result % 7.0;
          buffer.append(result);
      }
      System.out.println(buffer.toString());
  }
  
  
  public void print() {
      String st = "";
      double result = 1.0 / 7.0;
      st = st + result;
      while (result != 0) {
          result = result % 7.0;
          st = st + result;
      }
      System.out.println(st);
  } 
  </code></pre>