StringBuffer vs StringBuilder : Performance improvement figures
IN previous post StringBuffer vs StringBuilder , I have explained benefits of using StringBuilder over StringBuffer. Here are some performance figure using both for concatenating string. package com.test; public class StringConcatenateTest { public static void main(String[] args) { System.out.println( "Using StringBuffer" ); long bufferTime = usingStringBuffer(); System.out.println( "Using String Builder" ); long builderTime = usingStringBuilder(); double perc = (( double )(bufferTime-builderTime)/bufferTime)* 100; System.out.println( "Improved in performance = " + perc + "%" ); } public static long usingStringBuffer(){ long startTime = System.currentTimeMillis(); System.out.println( "\tStart time = " + startTime); StringBuffer sb = new StringBuffer(); for ( int i=0;i<1000000;i++){ sb.append( "\tSample ...