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 .
5 Réponses
+ 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
+ 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
+ 3
Python syntax is typically simpler / shorter. But you can do the same things in any language.