Stringbuilder common method

First, create Stringbuilder objects
StringBuilder strB = new StringBuilder ();

1、append(String str)/append(Char c):字符串连接
System.out.println("StringBuilder:"+strB.append("ch").append("111").append('c'));
//return "StringBuilder:ch111c"

2, toString (): Returns a string from the same construct or the buffer contents
System.out.println ( "String:" + strB.toString ());
// return "String: ch111c"

3, appendcodePoint (int cp): adding a code point, and convert it to one or two code units and return the this
System.out.println ( "StringBuilder.appendCodePoint:" + strB.appendCodePoint (2));
// return "StringBuilder.appendCodePoint: ch111c?"

4, setCharAt (int i, char c): i-th element is set to the code C (will be appreciated that the replacement) char character using ''
strB.setCharAt (2, 'D');
System.out.println ( "the StringBuilder .setCharAt: "+ strB);
// return" StringBuilder.setCharAt: chd11c ?? "

5、insert(int offset, String str)/insert(int offset, Char c):在指定位置之前插入字符(串)
System.out.println("StringBuilder.insertString:"+ strB.insert(2, "LS"));
//return "StringBuilder.insertString:chLSd11c"
System.out.println("StringBuilder.insertChar:"+ strB.insert(2, 'L'));
//return "StringBuilder.insertChar:chLLSd11c"

Remove the string between the start position (inclusive) to the end position (free):. 6, Delete (int startIndex, int endIndex)
System.out.println ( "StringBuilder.delete:" + strB.delete (2,. 4 ));
// return "StringBuilder.delete: chSd11c ??"

Reference to the original text: https://www.cnblogs.com/jack-Leo/p/6684447.html

Guess you like

Origin www.cnblogs.com/doyourwant/p/11374970.html