String 字符串处理
来源:互联网 发布:淘宝客去哪里推广 编辑:程序博客网 时间:2024/05/16 06:43
public class StringConcatTest extends TestCase{public static int COUNT = 100000 ;public void testString() {String result = "";long start = System.currentTimeMillis();for (int i = 0; i < COUNT; i++) {result = result + i;}long end = System.currentTimeMillis();System.out.println("用 + 耗时:\t" + (end - start));String result1 = "";start = System.currentTimeMillis();for (int i = 0; i < COUNT; i++) {result1 = result1.concat(String.valueOf(i));}end = System.currentTimeMillis();System.out.println("用 concat 耗时:\t"+(end - start));start = System.currentTimeMillis();StringBuffer buffer = new StringBuffer();for (int i = 0; i < 10000; i++) {buffer.append(i);}end = System.currentTimeMillis();System.out.println("用 StringBuffer 耗时:\t"+(end - start));start = System.currentTimeMillis();StringBuilder sb = new StringBuilder();for (int i = 0; i < 10000; i++) {sb.append(i);}end = System.currentTimeMillis();System.out.println("用 StringBuilder 耗时:\t"+(end - start));}}
测试结果
用 + 耗时:17517用 concat 耗时:8813用 StringBuffer 耗时:1用 StringBuilder 耗时:0
0 0
- 字符串处理string
- C++字符串string处理
- String 字符串处理
- String Successor(字符串处理)
- string 模块:字符串处理
- String 字符串处理
- UVa10391 string字符串处理
- String,字符串处理
- java 字符串处理String
- 字符串处理----String
- String字符串处理总结
- c++ string 处理字符串
- String类处理字符串
- 字符串处理之string
- C++字符串处理string
- String字符串处理
- 8.1 不变字符串String处理
- c++的字符串string处理
- 海量数据搜索的思考
- 40多个关于人脸检测/识别的API、库和软件
- poppler windows 编译 详解 心得
- android 获取内部存储器列表
- 前端开发学习随笔---------$.proxy()
- String 字符串处理
- Excel Sheet Column Number
- AsyncTask的版本兼容性与target sdk version
- PHP捕获Fatal error错误的方法
- Sublime Text 3 使用心得
- spring bean作用域
- Nginx+tomcat+ssl免费证书配置
- @Resource注解
- windbg - command manual