1 public class demo11 { 2 public static void main(String[] args) { 3 //StringBuilder可以看作为一个容器,创建之后里面内容可变 4 //1.创建对象
5 StringBuilder sb = new StringBuilder(); 6 //StringBuilder sb = new StringBuilder("abc"); 7 8 //2.添加元素 9 sb.append("abc"); 10 sb.append("ABC"); 11 sb.append("软萌小鲨鱼"); 12 13 14 //3.反转 15 sb.reverse(); 16 System.out.println(sb); 17 18 //获取长度 19 int lenth = sb.length(); 20 System.out.println(lenth); 21 22 //变回字符串 23 String str = sb.toString(); 24 System.out.println(str); 25 26 27 } 28 }
1 public class demo12 { 2 public static void main(String[] args) { 3 StringBuilder sb = new StringBuilder(); 4 sb.append("aaa").append("bbb").append("ccc"); 5 System.out.println(sb); 6 } 7 }
标签:StringBuilder,System,sb,public,append,out From: https://www.cnblogs.com/louwangshayu/p/17558308.html