API StringBuffer类例子

 1 package cn.zmh.Buffer;
 2 
 3 public class StringBufferDemo {
 4     public static void main(String[] args) {
 5         print3();
 6     }
 7     //append将任意类型添加到缓冲区
 8     public static void print(){
 9         StringBuffer bu = new StringBuffer();
10         bu.append(65).append("jfkajlf").append(true).append(10.5464);
11         System.out.println(bu);
12     }
13     //删除的时候结尾位置减去1;
14     public static void print1(){
15         StringBuffer bu = new StringBuffer();
16         bu.append("hslaskf");
17         bu.delete(1,3);
18         System.out.println(bu);
19     }
20     //insert插入
21     public static void print2(){
22         StringBuffer bu = new StringBuffer();
23         bu.append("hello");
24         bu.insert(2,"你好");
25         System.out.println(bu);
26     }
27     //replace 替换
28     public static void print3(){
29         StringBuffer bu = new StringBuffer();
30         bu.append("杰克逊每天都练舞蹈");
31         bu.replace(0,3,"mary");//替换
32         System.out.println(bu);
33     }
34     //reverse 反转
35     public static void print4(){
36         StringBuffer bu = new StringBuffer();
37         bu.append("我爱我家");
38         bu.reverse();
39         System.out.println(bu);
40     }
41     //toString
42     public static void print5(){
43         StringBuffer bu = new StringBuffer();
44         bu.append("我喜欢在白纸上画画 画出我笨拙的自由");
45         bu.append(156464464);
46         String s = bu.toString();
47         System.out.println(s);
48     }
49     
50 }

 

posted @ 2019-03-19 23:12  Java练习生  阅读(146)  评论(0编辑  收藏  举报