StringBuffer Performance









This  java  code   is    explain   performance  of the  StringBuffer and  StringBuilder  Performance .

 you  can see  the    output   execution  time  in mili seconds.






package Java8;

/** @author Mukesh Jha **/

public class StringBuilderandtringufferPerformance {
    public static void main(String[] args) {
        int N = 99999;
        long t;

        {
            StringBuffer sb = new StringBuffer();
            t = System.currentTimeMillis();
            for (int i = N; i --> 0 ;) {
                sb.append("");
            }
     
System.out.println("Stirng Buffer run time::" +(System.currentTimeMillis() - t));
        }

        {
            StringBuilder sb = new StringBuilder();
            t = System.currentTimeMillis();
            for (int i = N; i > 0 ; i--) {
                sb.append("");
            }
            System.out.println( "String Builder executin::" +(System.currentTimeMillis() - t));
        }
    }

}


StringBuffer Performance StringBuffer Performance Reviewed by Mukesh Jha on 1:25 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.