SHARE
TWEET

Java + vs. StringBuilder

a guest Jun 10th, 2013 31 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public static void main(String[] args) {
  2.                 int iterations = 10000;
  3.  
  4.                 long start = System.currentTimeMillis();
  5.                 String text = "";
  6.                 for (int count = 0; count < iterations; count++) {
  7.                         text += "Test" + "\n";
  8.                 }
  9.                 System.out.println("+ took: " + Long.toString(System.currentTimeMillis() - start) + "ms");
  10.  
  11.                 start = System.currentTimeMillis();
  12.                 StringBuilder builder = new StringBuilder();
  13.                 for (int count = 0; count < iterations; count++) {
  14.                         builder.append("Test").append("\n");
  15.                 }
  16.                 System.out.println("StringBuilder took: " + Long.toString(System.currentTimeMillis() - start) + "ms");
  17.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top