In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the summary of the usage of StringBuffer class in String". In the daily operation, I believe that many people have doubts about the summary of the usage of StringBuffer class in String. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "summary of the usage of StringBuffer class in String". Next, please follow the editor to study!
StringBuffer class
First, the string buffer is a container. You cannot inherit without subclasses.
Features: variable length; operable with multiple data types; can be changed into a string through toString ().
2. Storage method
1. StringBuffer append (); adds the specified data to the end of the existing data. No overloading of byte and short
StringBuffer sb = new StringBuffer ()
Sb.append (34) .append ("abc") .append ("de"); method call chain: this object is returned
Example:
StringBuffer sb = new StringBuffer ()
StringBuffer sb1 = sb.append (34)
Sop (sb==sb1) true the same object
Sop (sb.toString ()); 34
Sop (sb1.toString ()); 34
2. StringBuffer Insert (Index, any type of data) inserts the data into the specified Index location
Sb.insert (1, "hi")
III. Deletion method
StringBuffet Delete (int start,int end); contains the head but not the tail
StringBuffer deleteCharAt (int index); deletes the specified position character
Sb.delete (0menthsb.length ()) empties the buffer
IV. Acquisition method
Char charAt (int index)
Int indexOf (String str)
Int lastindexOf (String str)
Int length ()
String subString (int start,int end)
V. Modification method
Sb.replace (int start,int end,String str)
Sb.setChrAt (2) replaces a character
Void setCharAt (int index,char ch)
VI. Flip method
StringBuffer reverse ()
Save the contents of srcBegin to srcEnd in StringBuffer to the character array, starting with dstBegin
Void getChars (int srcBegin,int srcEnd,char [] dst,int dstBegin) eight: StringBuilder class
Appears after the JDK1.5 version
StringBuilder threads are not synchronized, StringBuffer thread synchronization is safe, and only one place is allowed to use
StringBuilder is faster, does not need to judge the lock, single-thread use
At this point, the study on the "summary of the usage of StringBuffer classes in String" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.