Here in this context We can
directly pass String class object to StringBuffer and StringBuilder class
constructors. As String class is immutable in java, so for editing a string, we
can perform same by converting it to StringBuffer or StringBuilder class
objects.
Example.java
package java8s;
public class Example {
public static void main(String[] args) {
String
str="SILAN";
//Conversion from String
object to StringBuffer
StringBuffer
sb1=new StringBuffer(str);
System.out.println(sb1);
sb1.reverse();
System.out.println(sb1);
//Conversion from String
object to StringBuilder
StringBuilder sb2=new StringBuilder(str);
sb2.append("Technology");
System.out.println(sb2);
}
}
Output:
SILAN
NALIS
SILANTechnology