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

Publicado el: 06 June 2019
en el canal de: 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


En esta página del sitio puede ver el video en línea Core Java Interview Questions - Difference Between String, StringBuffer and StringBuilder class #4 de Duración hora minuto segunda en buena calidad , que subió el usuario TechTalk Debu 06 June 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 332 veces y le gustó 5 a los espectadores. Disfruta viendo!