Unlike String, StringBuilder is mutable in nature. The API of this class is compatible with StringBuffer except that the StringBuilder is unsafe in a multithreaded environment. It is not synchronized so should it should not be used where thread safety is of prime concern.
String str = sb.toString();
☛ Next >> String vs StringBuffer vs StringBuilder
Let's have some basic idea about String, StringBuffer and StringBuilder. ...
It has two important methods append() and insert().
The append("x") function appends "x" at the end of existing StringBuilder.
The insert(5, "x") function inserts the string "x" at the provided index of existing StringBuilder. In this case, it is 5.
StringBuilder sb=new StringBuilder("Initial"); //Initial |
sb.append("Appended"); //InitialAppended |
sb.insert(7, "Inserted"); //InitialInsertedAppended |
To convert a StringBuilder to String we use toString() method.
String str = sb.toString();
☛ Next >> String vs StringBuffer vs StringBuilder
Let's have some basic idea about String, StringBuffer and StringBuilder. ...
No comments:
Post a Comment