JAVA (StringBuffer/StringBuilder)常用API

 1 public class Copy3 {
 2 
 3     public static void main(String[] args) {
 4         //构造实例化
 5         StringBuffer strbu = new StringBuffer("hello world	");
 6         char[] a = {'l','o','y','o','u'};
 7         //调用方法
 8         
 9         System.out.println(1+"	"+strbu.append(true));            //append(boolean b);
10         System.out.println(2+"	"+strbu.append('a'));            //append(char b);
11         System.out.println(3+"	"+strbu.append(a));                //append(char[] b);
12         System.out.println(4+"	"+strbu.capacity());            //capacity();
13         System.out.println(5+"	"+strbu.charAt(10));            //charAt(int index);
14         System.out.println(6+"	"+strbu.delete(3, 9));            //delete(int start, int end);
15         System.out.println(7+"	"+strbu.insert(5, false));        //insert(int offset, boolean b);
16         System.out.println(8+"	"+strbu.substring(7));            //substring(int start)
17         System.out.println(9+"	"+strbu.reverse() );            //reverse() 
18         
19     }
20 
21 }

运行结果

原文地址:https://www.cnblogs.com/-maji/p/7123248.html