The java string buffer StrgingBuffer StringBuilder

1.StringBuffer is a variable length or content container that can hold a lot of strings, and there are ways to operate on the string.

2. Operation

Create Object

1 StringBuffer buffer = new StringBuffer("abc");

2.1 the specified content (basic data types) increased string

1     buffer.append(1234).append(true).append(1.2);

2.2 Remove the specified character string length, the chain may be invoked, each call to obtain a new string

1          // delete data, in accordance with the number of the characters 
2          buffer.delete (2,. 3) .Delete (2,. 3); // start from the Table 2, no header trailer

2.3 at the specified position, insert the string

        // Insert 
        buffer.insert (2, "Peng"); // index from start 2

2.3 replacement string on the character string specified length

1          // Replace 
2          ; - buffer.replace (2, "mu123" 2, buffer.length ()) // the token packet does not include the front

2.4 The reverse string

buffer.reverse (); // reverse order printing 
buffer.toString (); // string output

Guess you like

Origin www.cnblogs.com/mlf19920916/p/12099132.html