which one is faster among string stringbuffer and stringbuilder?

StringBuilder is faster one among string, stringbuffer and stringbuilder.
Example

public class Main 
{ 
    long startTime = 0l;
    long endTime = 0l;
    long timeDiff = 0l;
    // Concatenates to String 
    public void concat1(String website) 
    { 
        startTime = System.nanoTime();
        website = website + ".com";
        endTime = System.nanoTime();
        timeDiff = endTime - startTime;
        System.out.println("Time taken by String: " + timeDiff);
    } 
 
    // Concatenates to StringBuilder 
    public void concat2(StringBuilder website) 
    {  
        startTime = System.nanoTime();
        website.append(".com"); 
        endTime = System.nanoTime();
        timeDiff = endTime - startTime;
        System.out.println("Time taken by StringBuilder: " + timeDiff);
    } 
 
    // Concatenates to StringBuffer 
    public void concat3(StringBuffer website) 
    { 
        startTime = System.nanoTime();
        website.append(".com");
        endTime = System.nanoTime();
        timeDiff = endTime - startTime;
        System.out.println("Time taken by StringBuffer: " + timeDiff);
    } 
 
    public static void main(String[] args) 
    { 
        Main object = new Main();
        String s1 = "w3spoint"; 
        object.concat1(s1);
 
        StringBuilder s2 = new StringBuilder("w3spoint"); 
        object.concat2(s2);
 
        StringBuffer s3 = new StringBuffer("w3spoint"); 
        object.concat3(s3); 
    } 
}

Output

Time taken by String: 19199 
Time taken by StringBuilder: 910 
Time taken by StringBuffer: 3650
Please follow and like us:
Content Protection by DMCA.com
togel situs toto situs togel situs toto situs toto agen togel situs togel situs togel togel situs togel resmi situs togel situs togel situs toto link togel togel online