Home  >  Article  >  Java  >  A brief discussion on the differences between String StringBuffer and StringBuilder in java

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

高洛峰
高洛峰Original
2017-01-22 11:42:351381browse

* 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!

Statement:
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