Core Java Interview Questions - Difference Between String, StringBuffer and StringBuilder class #4

Pubblicato il: 06 June 2019
sul canale di: TechTalk Debu
332
5

Difference Between String, StringBuffer, and StringBuilder
1. Objects of String are immutable, and objects of StringBuffer and StringBuilder are mutable.
2. StringBuffer and StringBuilder are similar, but StringBuilder is faster and preferred over StringBuffer for the single threaded program.
If thread safety is needed, then StringBuffer is used

// Java program to demonstrate difference between String,
// StringBuilder and StringBuffer
class StringDiff
{
// Concatenates to String
public static void concat1(String s1)
{
s1 = s1 + "Debu";
}

// Concatenates to StringBuilder
public static void concat2(StringBuilder s2)
{
s2.append("Debu");
}

// Concatenates to StringBuffer
public static void concat3(StringBuffer s3)
{
s3.append("Debu");
}

public static void main(String[] args)
{
String s1 = "Paul";
concat1(s1); // s1 is not changed
System.out.println("String: " + s1);

StringBuilder s2 = new StringBuilder("Paul");
concat2(s2); // s2 is changed
System.out.println("StringBuilder: " + s2);

StringBuffer s3 = new StringBuffer("Paul");
concat3(s3); // s3 is changed
System.out.println("StringBuffer: " + s3);
}
}

Follow me on FaceBook:   / techtalkdebu  
Instagram: techtalk_debu
and LinkedIn :   / debu-paul  


if you like my video, please subscribe to my channel and share the video

Thanks & Regards,
Debu Paul


In questa pagina del sito puoi guardare il video online Core Java Interview Questions - Difference Between String, StringBuffer and StringBuilder class #4 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato TechTalk Debu 06 June 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 332 volte e gli è piaciuto 5 spettatori. Buona visione!