By zeel ajadiya
Hello friends! In this Java tutorial, we are going to discuss String, StringBuffer, and StringBuilder, and also the difference between them using Java.
In Java language, the String class is nothing but an object that represents the array of char or sequence of char. Whereas StringBuffer is a class that represents the mutable(Modifiable), this is the same as a normal string except Strings are mutable in this case. Whereas StringBuilder also is a class that represents the mutable string, this is the same as StringBuffer except that it is non-synchronized.
We can create a String by using this:
String String_Example = "Hello World!";
We can create a StringBuffer by using this:
StringBuffer StringBuffer_Example = new StringBuffer("Hello World!");
We can create a StringBuilder by using this:
StringBuilder StringBuilder_Example = new StringBuilder("Hello world!");
Now let's compare the String, StringBuffer, StringBuilder:
As if we take an example then for concatenation operator (+) internally uses StringBuffer or StringBuilder class.
Submitted by zeel ajadiya (zeel)
Download packets of source code on Coders Packet
Comments