Java基础知识强化41:StringBuffer类之StringBuffer的反转功能
1. StringBuffer 的反转功能:
public StringBuffer reverse():
2. 案例演示:
1 package cn.itcast_05; 2 3 /* 4 * StringBuffer的反转功能: 5 * public StringBuffer reverse() 6 */ 7 public class StringBufferDemo { 8 public static void main(String[] args) { 9 // 创建字符串缓冲区对象 10 StringBuffer sb = new StringBuffer(); 11 12 // 添加数据 13 sb.append("霞青林爱我"); 14 System.out.println("sb:" + sb); 15 16 // public StringBuffer reverse() 17 sb.reverse(); 18 System.out.println("sb:" + sb); 19 } 20 }
运行结果如下: