码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA之StringBuffer测试样码

时间:2016-05-03 17:33:59      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

这类操作大同小异,但是,高手却能从String,StringBuilder,StringBuffer的应用场景和性能上,分析出其在JAVA编译和JVM上的实现过程差别。

我在CSDN上就看到一个高手分析过。

http://blog.csdn.net/clam_clam/article/details/6831345

http://www.cnblogs.com/dolphin0520/p/3778589.html

技术分享

public class StringBufferDemo {
  public static void main(String[] args) {
    System.out.println("----------------------");
    createString(new StringBuffer("hello java"));
    System.out.println("----------------------");
    deleteString(new StringBuffer("hello java"));
    System.out.println("----------------------");
    replaceString(new StringBuffer("hello java"));

  }
  public static void createString(StringBuffer stringBuffer) {
    stringBuffer.append("hello").append("java").append(520).append(true);
    System.out.println(stringBuffer);
    stringBuffer.insert(0, "heima,");
    System.out.println(stringBuffer);
  }
  public static void deleteString(StringBuffer stringBuffer) {
    stringBuffer.delete(0, 6);
    System.out.println(stringBuffer);
    stringBuffer.deleteCharAt(1);
    System.out.println(stringBuffer);
  }
  public static void replaceString(StringBuffer stringBuffer) {
    stringBuffer.replace(6, stringBuffer.length(), "world");
    System.out.println(stringBuffer);
    stringBuffer.setCharAt(5, ‘,‘);
    System.out.println(stringBuffer);
    stringBuffer.reverse();
    System.out.println(stringBuffer);
  }
}

技术分享

JAVA之StringBuffer测试样码

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5455456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!