灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2692回复:0

Java字符串详解

楼主#
更多 发布于:2012-09-08 09:41


也行你知道,也许你不知道
一:
[java]
@Test
public void test() {
    long start = System.currentTimeMillis();
    String str = "";
    for(int i = 0 ; i < 499990 ;i++){
        str = str+i;
    }
    long end = System.currentTimeMillis();
    System.out.println(start);
    System.out.println(end);
    System.out.println((double)(end-start)/1000);
}
1335404638171
1335406659968
2021.797
二:
[java] @Test
    public void test2() {
        long start = System.currentTimeMillis();
        StringBuffer str = new StringBuffer();
        for(int i = 0 ; i < 499999 ;i++){
            str.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println(start);
        System.out.println(end);
        System.out.println((double)(end-start)/1000);
    }
1335406936015
1335406936140
0.125
三:
[java]
@Test
    public void test2() {
        long start = System.currentTimeMillis();
        StringBuffer str = new StringBuffer();
        for(int i = 0 ; i < 1999999 ;i++){
            str.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println(start);
        System.out.println(end);
        System.out.println((float)(end-start)/1000);
    }
1335409426250
1335409426593
0.343
这下,你知道了吧





喜欢0 评分0
游客

返回顶部