A StringBuffer is like String but it can be modified because of its mutable nature. They are thread-safe and can be easily used in a multithreaded environment.
String str = sb.toString();
☛ Next >> StringBuilder in Java
Unlike String, StringBuilder is mutable in nature. The API of this cla ...
It has two important methods append() and insert().
The append("x") function appends "x" at the end of existing StringBuffer.
The insert(5, "x") function inserts the string "x" at the provided index of existing StringBuffer. In this case, it is 5.
StringBuffer sb=new StringBuffer("Initial"); //Initial |
sb.append("Appended"); //InitialAppended |
sb.insert(7, "Inserted"); //InitialInsertedAppended |
To convert a StringBuffer to String we use toString() method.
String str = sb.toString();
☛ Next >> StringBuilder in Java
Unlike String, StringBuilder is mutable in nature. The API of this cla ...
No comments:
Post a Comment