Home > Java > javaTutorial > body text

A brief discussion on the differences between String StringBuffer and StringBuilder in java

高洛峰
Release: 2017-01-22 11:42:35
Original
1429 people have browsed it

* The String class is an immutable class. As long as String is modified, a new object will be generated.

* StringBuffer and StringBuilder are both mutable classes, and any changes to the string will not create new objects.

In actual use, if you often need to modify a string, such as inserting, deleting, etc.

* But what is the difference between StringBuffer and StringBuilder?

StringBuffer is thread-safe and is very convenient to use in multi-threaded programs, but the efficiency of the program will be slower.

StringBuilder is not thread-safe and is more efficient than StringBuffer in a single thread.

* In summary, the running time of the three:

String > StringBuffer > StringBuilder

The above article briefly talks about String in Java. The difference between StringBuffer and StringBuilder is small. I have compiled all the content shared with you. I hope it can give you a reference. I also hope that everyone will support the PHP Chinese website.

For more articles on the differences between String StringBuffer and StringBuilder in Java, please pay attention to the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template