In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the difference between String, StringBuffer and StringBuilder of java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
As we all know, String can not be modified, because it is modified by final, unless a new object is generated, but we have a lot of string modification operations in our business, then StringBuffer and StringBuilder emerge as the times require, and objects of StringBuffer and StringBuilder classes can be modified many times without generating new unused objects. StringBuilder
StringBuilder is actually very fast, even much faster than StringBuffer, but it has a fatal disadvantage, that is, this method is not thread-safe. Because StringBuilder has a speed advantage over StringBuffer, it is recommended to use StringBuilder in most cases, but when the program as a whole requires thread safety, we must use StringBuffer.
In fact, for StringBuffer, I haven't come across a real usage scenario for so many years as a developer, because it's thread-safe, just keeping JVM running smoothly and not throwing exceptions further. Therefore, in general, in order to ensure thread safety, we need to use locks.
Probably because they didn't know what decision, before StringBuilder, the bosses of sun chose to make StringBuffer thread-safe. Then a few years later, JDK5 StringBuilder came into being, and from this time on, java began to become popular. I think StringBuilder also made a contribution to java to get rid of its slow speed.
To sum up, it is very simple, just the following:
The size and length of 1.String is immutable because it is modified by final.
2.StringBuffer and StringBuilder are of variable length.
3.StringBuffer thread safe StringBuilder thread is not safe.
4.StringBuilder is fast.
5. StringBuilder is used in general business situations.
6.StringBuilderJDK1.5 just got out.
This is the end of the content of "what's the difference between String, StringBuffer and StringBuilder of java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.