Example Analysis of StringBuilder usage in. NET and stringbuilder usage
This example describes the usage of StringBuilder in. NET. Share it with you for your reference. The specific analysis is as follows:
Why use StringBuilder?
accept arbitrary types of data. Each method effectively converts the given data into a string, and then appends or inserts the character of the string into the string buffer. The Append method always adds these characters to the end of the buffer, while the Insert method adds characters at the specified point. For example, if z refers to a string buffer object where the current content is "start", this method call Z.append ("le") causes the string bu
Before reading this essay, be sure to look at the previous two chapters:Java string, StringBuilder, StringBuffer common source analysis and comparison (a): String source code AnalysisJava string, StringBuilder, StringBuffer common source analysis and comparison (ii): StringBuilder, StringBuffer source analysisThis explains the three types of source code, but also
JAVA String, StringBuilder, and StringBuffer classes, java clears stringbuffer
The StringBuffer class (or StringBuilder) is the same as the String class and is also used to represent strings. However, because the internal implementation of StringBuffer is different from that of String, StringBuffer does not generate n
the Insert method adds the characters at the specified point.
For example, if z references a string buffer object where the current content is "start", the method call Z.append ("le") causes the string buffer to contain a "startle" (additive), while Z.insert (4, "le") changes the string buffer to include the " Starlet ".
In most cases StringBuilder > StringBuffer
Java.lang.StringBuilder A variable seque
specified character. The following example uses the Replace method to search for the StringBuilder object, find all the exclamation characters (!), and use the question mark character (?). To replace them.
Stringbuildermystringbuilder = new StringBuilder ("Hello world!");
Mystringbuilder.replace ('! ', '? ');
Console.WriteLine (Mystringbuilder);
T
the Java API documentation, we can use the tool to view the byte code commands for class files to get these answers. For example, code:
public static void Main (string[] args) {
String a = "Hello";
String B = "World";
String str = a + B + "!";
System.out.println (str);
The corresponding bytecode commands are viewed from the tool as follows:
From the bytecode command, we can see cl
Comparison of String, StringBuffer and StringBuilder in Java and source code analysisIt is well known that string, StringBuffer, and StringBuilder are common strings in Java, and I will compare the three brothers in three ways.the data organization and its function realization of the first and third peopleWe love the s
" + "simple" + "test";
StringBuffer Sb = new StringBuilder ("This was only a"). Append ("simple"). Append ("test");
The speed of generating a String S1 object is no slower than stringbuffer. In fact, in Java compiler, the following conversions are done automatically:Java compiler directly compiles the first statement above to:[Java]View Plaincopy
Fully explain the relationships between StringBuilder, StringBuffer, and String classes in java, bufferbuilderRelationship between StringBuilder, StringBuffer, and String classes
In java, String, StringBuffer, and StringBuilder are frequently used String classes in programmi
modifiedStringBuffer object references, for example:3) method public StringBuffer Delete (int start,int end) can delete a sequence of characters from start to End-1, returning the modifiedThe StringBuffer object reference.4) A method similar to the meaning of the string class:5) method Public StringBuffer reverse () is used to reverse the character sequence and return the modified StringBuffer object reference.Instance code:public class test{public
I believe that the difference between String and StringBuffer has also been very understanding, but it is estimated that there will be a lot of comrades on the working principle of these two classes are not clear, today I am here to review the concept for you, and by the way pull out J2SE 5.0 Inside brings a new character to operate the class--stringbuilder. So what are the differences between this StringBuilder
Java common classes: StringBuffer and StringBuilderA StringBuilder class (1) understand the StringBuilder class
In Java, in addition to using the String class to store strings, you can also use the StringBuilder class or StringBuffer class to store strings.
word into the sixth position of the StringBuilder.Stringbuildermystringbuilder = new StringBuilder ("Hello world!");Mystringbuilder.insert (6, "Beautiful");Console.WriteLine (Mystringbuilder);This example displays the Hello beautifulworld! to the console.(4) The Remove method can be used to remove a specified number of characters from the current StringBuilder a
direct addition of strings, the efficiency is very high, because the compiler determines its value, that is, the shape of "I" + "Love" + "Java"; Strings are added, and are optimized for "Ilovejava" during compilation. This can be verified by using the JAVAP-C command to decompile the generated class file.For the indirect addition (that is, contains the string reference), the shape is like s1+s2+s3; Efficiency is lower than the direct add, because the
Recently in the study of Java, encountered such a problem, that is, String,stringbuilder and stringbuffer the three class between what is the difference between them, their own from the Internet to search for some information, some understanding of the post here to tidy up, for everyone to watch, Also easy to deepen their learning process of these knowledge points of memory, if wrong, please correct me.The
1-Hierarchical inheritance2-Variable and immutable concepts3-string3.1-string is a very special class3.2-string literals vs. String objectsMethods of 3.3-string3.3.1-length ()3.3.2-concat (String)3.3.3-indexof (..)3.3.4-substring (..)3.3.5-replace3.3.6-Other Instances4-stringbuffer vs stringbuilder1-Hierarchical inheritanceWhen working with text data, Java provides three categories, including String, StringBuffer, and
initialization of the string class, Java provides special syntax, and typically is initialized with a constructor method.For example: StringBuffer s = new StringBuffer();The StringBuffer object that is initialized in this way is an empty object. If you need to create a StringBuffer object with content, you can use: StringBuffer s = new StringBuffer ("abc"); the contents of the StringBuffer object i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.