0

What is the use of StringBuilder class in Java?

StringBuilder use in java. I want the methods and its work inside a code . When it can be used ? . Can reverse method is only used in the string builder class .

12th Jan 2020, 1:04 PM
TeckgeekARJ
TeckgeekARJ - avatar
5 Réponses
12th Jan 2020, 6:35 PM
Saroj Patel
Saroj Patel - avatar
+ 9
String class is immutable where as StringBuilder is mutable. Also when compared to StringBuffer, StringBuilder is faster because it's not thread safe or you can say that it is not synchronized. Also String class doesn't have a reverse() but StringBuilder has. Take a look at this example. https://code.sololearn.com/cSxvqwkmm0zm/?ref=app
12th Jan 2020, 1:08 PM
Avinesh
Avinesh - avatar
+ 5
When you create a String or even mention a new string literal in the code (anything enclosed in quotation marks), Java will occupy a new piece of memory for it. If you have to construct a long text dynamically from several components and variables, StringBuilder is much more efficient. To check all the methods, look at the official api documentation! https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/StringBuilder.html
12th Jan 2020, 1:25 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Python syntax is typically simpler / shorter. But you can do the same things in any language.
12th Jan 2020, 1:46 PM
Tibor Santa
Tibor Santa - avatar